【问题标题】: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当我运行“git push”时,我得到“您当前分支的提示在其远程之后”,但当前分支没有上游跟踪分支
【发布时间】:2021-12-27 13:25:31
【问题描述】:

我正在这个本地分支 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


    【解决方案1】:

    你有一个名为X的本地分支,没有跟踪信息,所以没有对应的上游

    然后您尝试将其推送到origin 作为X。到目前为止一切都很好......但是那个遥控器中有一个具有该名称的分支,所以只有当它是快进时你的推送才会被接受,而事实并非如此。

    当您执行git pull 时,您尝试合并/重新定位跟踪分支,但您的X 没有!所以它失败了。

    你基本上有两种选择:

    1. 添加跟踪信息:当 git 在控制台中有用地打印:git branch --setup-upstream-to=origin/X X,然后 git pullgit statusgit mergegit rebsegit push 不带参数将默认到跟踪分支,并且它会按预期工作。
    2. 请拒绝添加跟踪信息。然后你必须执行完整的命令:git fetch origin,然后是 git rebase origin/Xgit merge origin/X,然后是 git push origin X

    由于您正在尝试git push -u,而-u 的意思是“添加跟踪信息”,我猜您想要选项1。

    【讨论】:

    • git branch --set-upstream-to=origin/X X 完成了这项工作,那时我只需要解决合并冲突,提交和推送
    猜你喜欢
    • 2013-03-19
    • 1970-01-01
    • 1970-01-01
    • 2014-09-11
    • 1970-01-01
    • 2017-11-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多