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 pushwithout any arguments, its behavior depends on the value of thepush.defaultsetting. The default value ofpush.defaultismatching, which, according togit help config, does the following:In other words, if your local repository has a branch named
acceptanceand the remote repository has a branch namedacceptance, thengit pushwill try to make the remoteacceptancebranch match youracceptancebranch even if you don’t haveacceptancechecked out.So, my guess is that you checked out
acceptanceat some point in the past, but someone else on the project (or maybe you from a different clone of the repository) pushed new commits toacceptance. This caused your localacceptancebranch to be behind the remoteacceptancebranch. Now whenever you typegit push, your Git tries to back up the remoteacceptancebranch to the version you have in your local repository.To fix, I recommend setting
push.defaulttosimple(orupstreamifsimpleisn’t available in your Git version — it was only added in 1.7.11).