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
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:
git branch --set-upstream-to=origin/X X
, then git pull
, git status
, git merge
, git rebse
, git push
without arguments will default to the tracking branch, and it will work as expected.git fetch origin
, then git rebase origin/X
or git merge origin/X
, and git push origin X
.Since you are trying git push -u
, and -u
means "add tracking information", I guess that you want option 1.