How can I completely empty the master branch in Git?

后端 未结 6 2333
猫巷女王i
猫巷女王i 2020-12-23 13:41

I would like to completely empty the master branch in Git. For now, I would also like to keep all other branches which have been branched from master.

Is this possib

6条回答
  •  清歌不尽
    2020-12-23 14:14

    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.

提交回复
热议问题