【问题标题】:How do I squelch "fatal: The upstream branch of your current branch does not match the name of your current branch"?如何压制“致命:您当前分支的上游分支与您当前分支的名称不匹配”?
【发布时间】:2014-11-15 20:35:51
【问题描述】:

关于如何更改push命令的参数以避免出现此消息的SO有一个相关问题:

fatal: The upstream branch of your current branch does not match the name of your current branch

我对如何压制消息本身很感兴趣, 无需更改本地/远程分支的名称或使用花哨的push 命令。

假设我有一个本地分支跟踪一个不同名称的远程分支:

user@home:~ git branch -vv
branch-name abcd1234 [remote/origin/branch-name] last commit message

现在我希望能够通过简单地输入 git push 来推送我已提交的更改。当我这样做时,我收到以下消息:

fatal: The upstream branch of your current branch does not match
the name of your current branch.  To push to the upstream branch
on the remote, use

    git push origin HEAD:remote/origin/branch-name

To push to the branch of the same name on the remote, use

    git push origin branch-name

即使名称不匹配,如何强制git 自动推送到上游分支?我正在使用git 1.9.1

【问题讨论】:

    标签: git


    【解决方案1】:

    较新的 Git(v 1.9 或更新版本)

    git config --global push.default upstream
    

    旧版 Git

    git config --global push.default tracking
    

    Git 2.3 仍然接受 tracking 作为上游的同义词

    只需执行一次,每当您“git push”时,它会将您当前的分支推送到其配置的上游。

    这也会在您的全局配置中设置它,这可能会被您的存储库配置中的不同设置所掩盖。

    【讨论】:

    • 谢谢 Andrew,我输入了该命令,然后输入了 git push 并得到了相同的消息。
    • 查看存储库.git/config文件或系统/etc/gitconfig中是否存在冲突设置
    • tracking 似乎最可疑:列出的 5 个可能值是 currentmatchingnothingsimpleupstream。在这种情况下,upstream 似乎是最需要的。
    • 跟踪和上游是一样的,我在回答中提到了这一点。 Git 在 1.7 和 2.0 之间的某个时候更改了名称,我不知道具体是什么时候。从 2.1 开始,跟踪仍然可以工作,但如果您配置上游并尝试使用 1.7 或更早版本,它肯定不会工作。
    • 谢谢,很难相信这不是默认行为。我跟踪这个远程分支是有原因的..
    猜你喜欢
    • 2014-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-05
    • 2023-03-09
    • 2017-09-30
    • 2021-12-27
    相关资源
    最近更新 更多