Alessandro Ghedini /dev/random

Creating an empty git branch

Sometimes I need to create an empty branch that do not share an ancestor with one of the other branches.

This can be achieved with the following commands:

$ git symbolic-ref HEAD refs/heads/branchname
$ rm .git/index
$ git clean -fd

Or alternatively:

$ git checkout --orphan branchname
$ git rm -rf .

That’s it. Now just do some some work and commit to the branch.