How to Create an Empty Branch in Git

0 min read 100 words

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>

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>
Tags:
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags