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 master to a 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 --ignore-date flag to rebase:

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

As a git alias: 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 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 BAK_:

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.