Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

push to branch without fetching update from other repository

Tags:

git

github

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

like image 432
user1937021 Avatar asked Oct 24 '25 11:10

user1937021


1 Answers

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.

like image 113
Amedee Van Gasse Avatar answered Oct 27 '25 00:10

Amedee Van Gasse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!