Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

This question already has an answer here:

My local repo is the latest one, then the GitHub repo is a little older, and then there's another repo that is the oldest, and I made some temporary changes to the oldest repo, then accidentally pushed to GitHub (what i wanted was to push the local one to GitHub).

Now, what I want to do is to reset hard on the GitHub repo to undo the accidental commit as if nothing ever happened, how should I do it? Should I pull the GitHub repo inside a new folder and then revert it and then push it back to GitHub?

share|improve this question

marked as duplicate by Cupcake, random, madth3, Jeff Bowman, Fraser Jul 27 '13 at 20:32

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Find the SHA1 of the commit you want to be the latest one on the github repo. This will probably be the commit right before the ones you didn't want to push.

Then on your old repo do: git reset --hard git push --force origin master

(or whatever remote and branch names you have)

This should do the job. Also make sure that everyone who has pulled/cloned the "bad" commit too removes it using these commands, otherwise it'll get pushed again when they push.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.