Git orphan branch

Given a Git repository with a commit history:

$ git status
On branch master
nothing to commit, working directory clean
$ git log --oneline

Is it possible to create a new branch with no commits?

Well, with the orphan option, you definitely can!

$ git checkout --orphan orphan
Switched to a new branch 'orphan'

Delete all your existing files:

$ git rm -rf .

And now you have a branch with zero commits and files.

$ git status
On branch orphan
Initial commit
nothing to commit (create/copy files and use "git add" to track)

Please support this site and join our Discord!