git - Updates were rejected because the remote contains work that you do not have locally

ID : 20076

viewed : 37

Tags : gitversion-controlmergecommitbitbucketgit

Top 5 Answer for git - Updates were rejected because the remote contains work that you do not have locally

vote vote

94

You can override any checks that git does by using "force push". Use this command in terminal

git push -f origin master

However, you will potentially ignore the existing work that is in remote - you are effectively rewriting the remote's history to be exactly like your local copy.

vote vote

89

git pull <remote> master:dev will fetch the remote/master branch and merge it into your local/dev branch.

git pull <remote> dev will fetch the remote/dev branch, and merge it into your current branch.

I think you said the conflicting commit is on remote/dev, so that is the branch you probably intended to fetch and merge.

In that case, you weren't actually merging the conflict into your local branch, which is sort of weird since you said you saw the incorrect code in your working copy. You might want to check what is going on in remote/master.

vote vote

73

It happens when we are trying to push to remote repository but has created a new file on remote which has not been pulled yet, let say Readme. In that case as the error says

git rejects the update

as we have not taken updated remote in our local environment. So Take pull first from remote

git pull 

It will update your local repository and add a new Readme file. Then Push updated changes to remote

git push origin master 
vote vote

68

This usually happens when the repo contains some items that are not there locally. So in order to push our changes, in this case we need to integrate the remote changes and then push.

So create a pull from remote

git pull origin master 

Then push changes to that remote

git push origin master 
vote vote

57

Force to push

git push -f origin master

Top 3 video Explaining git - Updates were rejected because the remote contains work that you do not have locally

Related QUESTION?