error: failed to push some refs

Asked

Viewed 59,817 times

8

trying to push to the repository and being rejected

$ git push origin master
To https://github.com/me/myproject
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/me/myproject'
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.
  • 1

    Updates were rejected because the remote contains work that you do not have locally (...) You may want to first integrate the remote changes (e.g., 'git pull ...') before pushing again.

2 answers

19


You’re trying to upload changes to a remote git, but on the remote server there are newer changes than yours, which you don’t have on your site yet. So before you push, you need to pull/pull the changes from there:

git checkout <branch> && git pull origin HEAD

This way, your local repository will be updated with the remote changes.

If any file that has been changed by you has also been changed on the remote, you will need to resolve possible merge conflicts before you push/push your pro remote changes.


Read carefully: if you don’t want the changes that are on the remote, and want to overwrite everything that is there with the local repository, use CAREFULLY the command below.

git push origin HEAD --force-with-lease

3

Your local repository is not compatible with the online repository.

First of all: remove the files modified by you and put them in any directory.

After this is done run the command:

git remote update #vai atualizar os branches locais com as copias do repositório online

Then turn:

git reset upstream/master

Ready, your reset is updated. Now go back with your modified files to the directory where you want and network the command:

git pull -r upstream master

This will bring everything back from the master and put your change on top. Then just send the push for your origin/<branchname> with --force.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.