4

I went to push work to my master branch but I get this error:

 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/Machinas/esprit-rwd'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushin
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

I don't want to fetch the update another person commited as it was a mistake on their part, how can I just push and ignore that commit? Thanks

user1937021
  • 10,151
  • 22
  • 81
  • 143
  • possible duplicate of [Force "git push" to overwrite remote files](http://stackoverflow.com/questions/10510462/force-git-push-to-overwrite-remote-files) – Amedee Van Gasse Jul 13 '15 at 07:38

1 Answers1

10

If you are really really sure that the other commits are not relevant, you can do a force push:

git push --force-with-lease <remote> <branch>

WARNING: if anyone else has already pulled the wrong commit, you will make them unhappy. And the person who made the wrong commit, should better get a new clone of your repo.

EDIT: changed --force to --force-with-lease because the latter is a bit less dangerous. This Atlassian blog post explains why.

Amedee Van Gasse
  • 7,280
  • 5
  • 55
  • 101