Reputation: 551
Right now I have a repo called playGround
It has 3 commits recorded
My local copy of playGround is behind 1 commit
I also have a branch called SecondB which was copied from my local copy of playGround. Then on SecondB I made two changes so SecondB has a total of 4 commits to it.
git remote show origin:
HEAD branch: master
Remote branches:
SecondB tracked
master tracked
Local branches configured for 'git pull':
SecondB merges with remote SecondB
master merges with remote master
Local refs configured for 'git push':
SecondB pushes to SecondB (up to date)
master pushes to master (local out of date)
My question is when I am on the SecondB branch and try to push it will give me this error:
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'url for repo'
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.
unless I specify what to push to like : git push origin SecondB
while I am on SecondB
How come I cannot simply do git push
as I am on SecondB and have it push to the remote copy of SecondB?
OKAY NEW INFORMATION: Upon examining the errors further it seems that every time I try to git push it tries to push to the remote branch AND the remote MASTER. Why is this behavior happening? and how would I fix this?
Upvotes: 1
Views: 404
Reputation: 60275
Change push's default behavior with the push.default
config setting.
Upvotes: 1
Reputation: 124646
When you run git push
without other parameters, it tries to push all the local branches that are tracking a remote branch. In your example it's master
and SecondB
. But your local master
is behind the remote master
, so it cannot be pushed. That's why the command fails.
You can only push with git push
if all tracking branches are ahead or in sync with their remote counterparts.
Upvotes: 1
Reputation: 30212
It's because you haven't merged the local branch you are trying to push with the current content of the remote branch you are trying to push into. In this case git is trying to get you to merge it before you push. Normally you would fetch/merge (or pull) then you would be able to push without problems. If you want to forget about that revision that you don't have and make the remote have the branch as you have it locally, you could use git push -f
Upvotes: 0