I am working on this local branch X and when I try to push using git push -u origin X
the error message is :
! [rejected] X -> X (non-fast-forward)
error: failed to push some refs to "********"
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
So I run : git pull
And an error message also appear :
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> X
CodePudding user response:
You have a local branch named X
, without tracking information, so there is no corresponding upstream.
Then you are trying to push it to origin
as X
. So far so good... but there is a branch in that remote with that name, so your push is only accepted if it is a fast-forward, which it is not.
When you do git pull
you try to merge/rebase the tracking branch, but your X
does not have one! so it fails.
You have basically two options:
- Add the tracking information: as git helpfully prints in the console:
git branch --setup-upstream-to=origin/X X
, thengit pull
,git status
,git merge
,git rebse
,git push
without arguments will default to the tracking branch, and it will work as expected. - Kindly refuse to add tracking information. Then you must do the full commands:
git fetch origin
, thengit rebase origin/X
orgit merge origin/X
, andgit push origin X
.
Since you are trying git push -u
, and -u
means "add tracking information", I guess that you want option 1.