简体   繁体   中英

Github - Git Push Error

So I am on a branch called 'test_branch'.

I do git add . and git commit and everything works fine.

But when I do git push , it gives me the error :

! [rejected]        acceptance -> acceptance (non-fast-forward)
error: failed to push some refs to 'git@github.com:company/sample.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.

Doing git pull shows me that everything is up-to-date, and doing a push after that, gives me the same error as above.

Can somebody please help me with this ?

Thanks.

When you type git push without any arguments, its behavior depends on the value of the push.default setting. The default value of push.default is matching , which, according to git help config , does the following:

matching -- push all branches having the same name in both ends. This is for those who prepare all the branches into a publishable shape and then push them out with a single command. It is not appropriate for pushing into a repository shared by multiple users, since locally stalled branches will attempt a non-fast forward push if other users updated the branch.

In other words, if your local repository has a branch named acceptance and the remote repository has a branch named acceptance , then git push will try to make the remote acceptance branch match your acceptance branch even if you don't have acceptance checked out.

So, my guess is that you checked out acceptance at some point in the past, but someone else on the project (or maybe you from a different clone of the repository) pushed new commits to acceptance . This caused your local acceptance branch to be behind the remote acceptance branch. Now whenever you type git push , your Git tries to back up the remote acceptance branch to the version you have in your local repository.

To fix, I recommend setting push.default to simple (or upstream if simple isn't available in your Git version -- it was only added in 1.7.11).

There probably is a branch you have to merge with to be able to push a fast-forwardable commit. To find out, first do

$ git fetch

Then do

$ git log --graph --decorate --oneline --all

You should see that the branch you are trying to push is not in the same line and ahead of the remote branch you are trying to merge with.

By the way, git push by itself always pushes all of your tracked branches to their origin/ counterparts, and you might have branches that aren't up to date with their origin counterparts. In that case, just ignore the warning. You can make this warning less wordy by:

$ git config advice.pushNonFastForward false

But I now see that your real problem is probably that test_branch doesn't get pushed with git push . To fix that, type:

$ git branch --set-upstream test_branch origin/test_branch

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM