Create the backup
branch.
git checkout master
git branch backup
If you want to keep one or more of the original commits on master
, then you can just use reset
to move the master
branch to an earlier commit. You need a name for the target commit. This could be the commit ID. Or if you know that it's, say, 5 commits before the commit at the current tip of the master
branch, you could say master~5
. If the name were T
you would say
git reset --hard T
If you don't want master
to keep any of the existing commits, then instead you can do this:
git checkout --detach
git branch -D master
git checkout --orphan master
This will revert master
to the state of an "unborn" branch, and your next commit will start a new history. Don't forget that your work tree and index may still contain state from the backup
branch, so make sure you get the index looking how you want it before committing.