简体   繁体   中英

When I run "git push" I get "tip of your current branch is behind its remote" but the current branche has no upstream tracking branch

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:

  1. Add the tracking information: as git helpfully prints in the console: git branch --setup-upstream-to=origin/XX , 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.
  2. Kindly refuse to add tracking information. Then you must do the full commands: 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.

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