09 Jul 2018
Hot to reset / reinitialise a git repository
It’s quite rare that you’d need to do this and the steps below are not recommended unless you absolutely don’t need anything in the repo you are about to nuke. My use case was I was moving a repo from one account to another and I didn’t want to transfer the repo. So repo A (the one with the correct data) to repo B (the new home for repo A).
Unfortunately, repo B had a few test commits in it from some time back. If I was to migrate the data from repo A into repo B with these commits still in place then git was getting confused and putting the master line from repo A into one of the branches in repo B which isn’t what I wanted.
So here’s how I fixed it:
- Checkout the repo you want to reset/clean/reinitialise/wipe/nuke to a local temp directory
- Open the git command line in that repo and run:
git rebase -i --root
- This will open a text file with the list of commits
- Change “pick” to “drop” on each of the commit lines
- Save and close the file – the updates should be made
- Run:
git push origin +master
- The changes should now be deleted