How to Create an Empty Branch in Git

If you need to create an empty branch in git, you can follow one of the below options.

If you are using git version 2.27 or newer, then follow the switch route (option 1) below, otherwise fall back to the older way, using checkout and delete (option 2).

Newer way – Using switch:

git switch --orphan <new branch> git commit --allow-empty -m "Initial commit on orphan branch" git push -u origin <new branch>
Code language: Bash (bash)

Older way – Using checkout and delete:

git checkout --orphan <new branch> git rm -rf . git commit --allow-empty -m "root commit" git push origin <new branch>
Code language: Bash (bash)
Tags:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments