当我运行“git Push”时,我得到“当前分支的提示位于其远程后面”,但当前分支没有上游跟踪分支

问题描述 投票:0回答:2

我正在这个本地分支 X 上工作,当我尝试使用

git push -u origin X 
进行推送时 错误消息是:

! [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.

所以我跑了:

git pull 
并且还出现错误消息:

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
git github push git-branch pull
2个回答
15
投票

您有一个名为

X
的本地分支机构,没有跟踪信息,因此没有对应的上游

然后您尝试将其推至

origin
作为
X
。到目前为止一切顺利...但是该遥控器中有一个具有该名称的分支,因此只有在快进时您的推送才会被接受,但事实并非如此。

当您执行

git pull
时,您尝试合并/变基跟踪分支,但您的
X
没有!所以失败了。

您基本上有两个选择:

  1. 添加跟踪信息:git 会在控制台中打印:
    git branch --set-upstream-to=origin/X X
    ,然后
    git pull
    git status
    git merge
    git rebse
    git push
    不带参数将默认为跟踪分支,并且它将按预期工作。
  2. 请勿添加追踪信息。然后,您必须执行完整命令:
    git fetch origin
    ,然后是
    git rebase origin/X
    git merge origin/X
    ,以及
    git push origin X

由于您正在尝试

git push -u
,并且
-u
表示“添加跟踪信息”,我猜您需要选项 1。


0
投票

这个解决方案确实有效。谢谢

© www.soinside.com 2019 - 2024. All rights reserved.