I have two local repos: a-public-project
and top-secret
, after making numerous commits to both local repos I then created a new empty repo on GitHub which will be the remote for a-public-project
, however I accidentally pushed top-secret
instead:
cd C:/Git/top-secret
git remote add github https://github.com/me/a-public-project.git
git push -u github master
In panic mode, I searched online and found these results:
- Undoing a 'git push'
- Git: permanently remove few commits from remote branch
- Is there a way to rollback my last push to Git?
- http://christoph.ruegg.name/blog/git-howto-revert-a-commit-already-pushed-to-a-remote-reposit.htmlbranch
Unfortunately, all of these involve resetting my local branch and doing git push --force
: this assumes there's a good intentional commit that I can rollback to. In this case, I don't - the entire repo history is bad and the remote repo needs its history deleted (but my local repo history untouched, obviously).
Fortunately, in this particular instance I was able to delete the repo using the GitHub website and then push the correct local repo, but what should I do if this happens again with a repo I don't control?