Git backup branches

Posted by on July 6, 2012

I always work on branches with Git making small micro commits, then rebase master onto the branch. I keep master shippable and only rebase from

1
master
to a
1
topic/feature branch
. I like for my commits to be kept at the top of the topic/feature branch (squashing them if possible).

I’ve recently adopted passing

1
--ignore-date
flag to rebase:

1
$(branchA) git rebase master --ignore-date

As a git alias:

1
rid = rebase master --ignore-date

This is great and automatic, but what if something goes wrong?

Make a backup

There are many ways to manage this, and I often push to

1
origin
branches for an offsite “backup” of my branch. I wanted a way to have a local backup branch.

Here is a git alias to create a branch with a prefix of

1
BAK_
:

1
bak = !git branch `git br | grep '*' | sed -e 's/* /BAK_/'`

Before rebasing, I make a backup copy of the branch in it’s exact state. If the branch is corrupt, I can delete the it and rename the backup to the original.