开发者

Git: failed to push some refs although I have done git pull

I started to get 'failed to push some refs' error when I changed some files and tried to do push. Most instructions tell to do git pull first. I have done it and git says everything is up to date. Any idea how to solve the error? I also started getting 'no version information available' message, I don't know does that have anything to do with the error.

git push origin master
git: /usr/local/lib/libz.so.1: no version information available (required by git)
Enter passphrase for key '/root/.ssh/id_rsa': 
To git@[mydomain].beanstalkapp.com:/repo-git.git
! [rejected]        master -> m开发者_运维技巧aster (non-fast forward)
error: failed to push some refs to 'git@[mydomain].beanstalkapp.com:/repo-git.git'


The error is that somebody else has pushed in the master branch and you would overwrite their change if git allowed you to push (this is what non-fast forward error means). So you need to merge your local master branch with the remote master branch.

This can happen if you did the git pull while the local branch was not the master branch. If you only want to push the branch you are working on and not the master branch, you need to tell it to git using the complete form of git-push:

$ git push remote local-branch:remote-branch


The best possible answer is on Git help here

Dealing with non-fast-forward errors

From time to time, you may encounter this error while pushing commits (git push origin master) to GitHub:

To https://github.com/user/repo.git  
 ! [rejected]        master -> master (non-fast-forward)  
error: failed to push some refs to 'https://github.com/user/repo.git'  
To prevent you from losing history, non-fast-forward updates were rejected  
Merge the remote changes (e.g. 'git pull') before pushing again.  
See the  'Note about fast-forwards' section of 'git push --help' for details.

This error can be a bit overwhelming at first; do not fear!

Simply put, Git can't make the change on the remote without losing commits, so it refuses the push. Usually, this is caused by another user pushing to the same branch.

You can remedy this by fetching and merging the remote branch:

git fetch origin
git merge origin master

Or, you can simply use git pull to perform both commands at once:

git pull origin master

In some cases, this error is a result of destructive changes made locally by using commands like git commit --amend or git rebase. While you can override the remote by adding --force to the push command, you should only do so if you are absolutely certain this is what you want to do. Force-pushes can cause issues for other users that have fetched the remote branch, and is considered bad practice. When in doubt, don't force-push.


Be sure your branch is unprotected, or developer can push is checked.


Be sure to verify that the pull actually worked. It is possible the merge (which is part of a pull) failed.

When I had this error message I failed to notice the pull failed. The pull failed due to some uncommitted file changes (unrelated to the files I was trying to push) which caused the merge to fail. I reverted those file changes (because they were not important) and then did a pull again. After the successful pull, the push worked.


Also, the error happens when you put the wrong branch name into your push command.

For example, say you're on a branch called iss8, but you tell git to push to iss3 (like I just did), you'll get the same error.

$ git push origin iss3
error: src refspec iss3 does not match any.
error: failed to push some refs to 'git@myhost.com:myuser/myproject.git'

Hmm, check status:

$ git status 
On branch iss8
nothing to commit, working directory clean

Oh, look, I'm on a different branch. Thanks git for not letting me do something really dumb.

$ git push origin iss8
Counting objects: 15, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (9/9), done.
Writing objects: 100% (9/9), 2.62 KiB | 0 bytes/s, done.
Total 9 (delta 3), reused 0 (delta 0)
To git@myhost.com:myuser/myproject.git
 * [new branch]      iss8 -> iss8


1) git stash 
2) git pull
3) git push

My Original Error:

Git: failed to push some refs although I have done git pull

After "git stash"

Git: failed to push some refs although I have done git pull


try this command git push -f origin master

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜