Create an empty git branch

If a new git branch is created the code base is the same as in the master branch but sometimes you want to create an empty git branch without any ancestors.

Scott Chacon shows in The Git Community Book how this is done.

The trick is that no matter in what branch you are currently you just need to set the HEAD reference to your desired branch name and deleting the old git index.

From the master branch (or any other) you execute the following commands.

git symbolic-ref HEAD refs/heads/playground 
rm .git/index 
git clean -fdx 

In this example playground will be the new empty git branch. Adapt the reference refs/heads/playground to whatever you want it to be, e.g. refs/heads/your-new-branch.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>