Skip to content

Creating an Orphan or Empty Git Branch

Mar 3, 2023 1 min read #git

This post is more than 18 months old. Technology changes quickly, so some of this content may be out of date (but that's not always the case). Please verify any technical or programming information against the current release.

Sometimes you may want to make a completely empty git branch in your repo. This is how you can do it.

git checkout --orphan new_branch_name
git rm -rf .
bash

Why? You may end up wanting to create a v2 or the next version of your application, yet retain all of the history in the same repo. If you’re starting from scratch you can do this. For example, I’ll be doing this when I convert the blog from Jekyll to Hugo.

First, this creates a new branch as an orphan. Then the existing files from the old branch still need to be unstaged and removed. That’s where the rm rf comes from.