How can I completely empty the master branch in Git?
That's actually called "delete old master branch and create new from scratch"
This will create a new master branch pointing to initial commit:
git branch -D master
git checkout -b master <initial commit hash>
This will create a totally new master branch unrelated to whatever you had:
git branch -D master
git checkout --orphan master
git rm -rf *
But actually you can simply save current repository to some other place and create a new repository instead.
Create an Orphan Branch
First, you need to move or delete your current master branch. Personally, I prefer to move it aside rather than delete it. After that, you simply create a new branch with no parents by using the --orphan
flag. For example:
git branch -m master old_master
git checkout --orphan master
Since the current branch now has no history, some commands may fail with errors like fatal: bad default revision 'HEAD'
until after you make your first commit on the new master branch. This is normal, and is the same behavior you see in freshly-initialized repositories.