Skip to Content

Creating an Empty Git Branch

Posted on One min read

Every now and then I find myself wanting to create a new empty branch in an existing repository. It’s useful for things such as Github Pages so you’re able to keep your content source in the master branch while only keeping the output in the gh-pages branch. I’ve also used it for testing a complete rewrite of a code base without the overhead of creating a new repo and copying access permissions.

This is a pretty straight forward trick to do. You create the brach by indicating you want the new branch to be an orphan by passing the ‘–orphan’ flag like so:

git checkout --orphan NEW_BRANCH_NAME

This leaves all the files in place but effectively uncommitted like you just initialized a new repository. Add and commit any files you’d like to keep then delete the rest, everything will still be preserved in the original branches.

With that done you should be able to easily switch just using a normal ‘checkout’ between your normal branches and this new tree.