I get this error every time I git push. Only for this working directory. Not in another similar one, where from what I can tell has the same permissions.
$ git push
Counting objects: 15, done.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (8/8), 683 bytes, done.
Total 8 (delta 5), reused 0 (delta 0)
remote: Sending mail...
To git@devel.site.com:mysite.git
dd36358..86bc572 redesign -> redesign
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@devel.si开发者_运维问答te.com:mysite.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.
Is this a permissions issue? git pull seems to work fine and git push seems to go through too but I still get the error.
Any ideas?
Ahem
Merge the remote changes (e.g. 'git pull') before pushing again.
This really doesn't look like a permissions problem to me.
It's not a permissions issue; see the error message:
error: failed to push some refs to 'git@devel.site.com:mysite.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.
The "note about fast-forwards" section of git push --help
has a lengthy explanation of the problem, but in short; the branch you're pushing to isn't a direct ancestor of your current branch, so the remote server won't let you push. You need to fix your local changes (e.g. git pull
to get changes you're missing, or git rebase
to rebase your changes onto the remote head), or force the remote server to accept the push with --force
(the latter is almost never the right move)
In case this is still a problem, if you do git push
, you're pushing all your branches, not just the current one.
git pull
is NOT a direct opposite to git push
, however. It is exactly the same as doing the following commands:
git fetch
git merge origin/thecurrentbranch
That is, git pull
only merges the working branch. It does NOT merge any other branches.
If git pull
comes up clean, but you still can't push, it means that one of your other branches is out of date, and that's what git is complaining about.
The solution is to only push your current branch:
git push origin thecurrentbranch
Note that I assume thecurrentbranch
is the name of your active branch, and origin
is your up-stream repository.
EDIT: Taking a close look at your original question is enlightening:
dd36358..86bc572 redesign -> redesign
! [rejected] master -> master (non-fast-forward)
You probably have redesign
checked out, and so this is what git pull
is operating on. However, git is rejecting the master
branch. So, to resolve this specific problem, either push redesign
explicitly, or do this:
git checkout master
git merge origin/master
git push
精彩评论