This article outlines the process of creating an empty git branch on the command line. We will then push the empty branch to a GitHub repository.
We know we cannot push an empty branch to a remote repository. However, there is a way around this.
Create an Empty Branch on GitHub
The example below shows a local repository with a
master branch. We want to create an empty
release branch in our repository.
Of course, we cannot create an empty branch the conventional way. If we do, we will create a
release branch with the commit history borrowed from our
We will use the command below to create an empty
$ git switch --orphan release
This should create an empty branch without commits or files. Let’s run the
git log command to confirm our case.
We now have an empty
release branch. Since we cannot push an empty branch to the remote, we will have to create an empty commit in our
$ git commit --allow-empty -m "Initial commit on orphan branch"
This will create a commit that does not have any files. We can now push the branch to the remote, as shown below.
$ git push -u origin release
This should push our empty branch to our remote repository on GitHub. Let’s verify if this is the case.
There you have it. An empty release branch on GitHub.
In a nutshell, you can create an empty branch using the
--orphan flag with the
git switch command. You can also use the
git checkout command, but you must clean your index before committing.
Failure to which you will create a commit with the files present on your index.