AndreaNobili
AndreaNobili

Reputation: 42957

How to ignore the remote changes during a GIT push?

I am having the following problem trying to push a project on GIT.

Pushing it I obtain this error message:

$ git push origin master
To https://bitbucket.org/MyAccount/my-project.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://[email protected]/MyAccount/my-projec.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
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.

So it seems, correct me if I am doing wrong assertion, that on my remote repository there are changes that I have not taken in my local repository and it suggest me to perform a pull to obtain these changes.

This is a problem for me because the local version is the last definitive version of my application and I can not risk it to overwrite something taking something old and wrong (or made by someoneelse) from the remote repository.

Can I specify to push the local content without taking into account the remote changes? Or how can I check the difference between my last local commit and the remote content?

Upvotes: 4

Views: 8724

Answers (1)

Marina Liu
Marina Liu

Reputation: 38106

Yes, as you understand, it’s because remote master branch has new versions (maybe pushed by your coworkers). And you can’t ignore the new version except you push by force, this will cause the new version lost.

You should pull the new version from remote to local, and rebase your unpushed commits on the top of new version and keep conflict files as your local versions if there has conflict during git pull, the command you can use

git pull origin master --rebase -X theirs

You can use tracking branches to check if remote has new versions. master branch is usually tracking to origin/master (you can check by git branch –vv). Then you can use git status, git will compare between local master and remote branch.

Upvotes: 8

Related Questions