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>