Skip to content

Git: Create an Empty Branch

Last updated on November 22, 2022

You can create an empty new branch with the --orphan option to the git checkout command.

$ git checkout --orphan <branch name>

By the above command, you will be able to create a new branch and directly checkout to the new branch. It will be a parentless branch.

Now the empty branch is created locally, you have to push this to the remote server. If you have files in your working directory you can remove them with the rm command as shown below.

$ git rm -rf .
$ git commit --alow-empty -m "Initial commit"
$ git push origin <your empty branch name>

If you want to merge another branch, use the --allow-unrelated-history option to force the merge into the empty branch.

$ git merge --allow-unrelated-history <branchName>

Comments are closed, but trackbacks and pingbacks are open.