1

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:

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?

Community
  • 1
  • 1
Dai
  • 141,631
  • 28
  • 261
  • 374

1 Answers1

2

one quick way to recover would be to delete the master branch from the remote

git push github :master

or you could quickly hop over to a-public-project and force push that to overwrite

cd C:/Git/a-public-project
git remote add github https://github.com/me/a-public-project.git
git push -u github master --force
Jeff Puckett
  • 37,464
  • 17
  • 118
  • 167
  • 1
    I see the significance of the colon here: http://stackoverflow.com/questions/7303687/why-git-use-the-colon-branch-to-delete-remote-branch – Dai Jul 13 '16 at 02:29