【问题标题】:how to address Git error "the requested upstream branch 'upstream/master' does not exist"如何解决 Git 错误“请求的上游分支 'upstream/master' 不存在”
【发布时间】:2017-05-15 17:00:38
【问题描述】:

我正在尝试按照一些步骤为 GitHub 上的存储库做出贡献,但其中一个步骤不起作用。步骤在这里:https://github.com/wdbm/qTox/blob/master/CONTRIBUTING.md#how-to-open-a-pull-request

我在 GitHub 上 fork 存储库。

我克隆了存储库:

git clone https://github.com/<YOUR_USER>/qTox.git

我访问本地仓库的目录:

cd qTox

我添加上游远程以便能够从上游存储库中获取:

git remote add upstream https://github.com/qTox/qTox.git

我尝试将本地 master 分支指向上游存储库:

git branch master --set-upstream-to=upstream/master

此命令失败并显示以下错误消息:

error: the requested upstream branch 'upstream/master' does not exist
hint: 
hint: If you are planning on basing your work on an upstream
hint: branch that already exists at the remote, you may need to
hint: run "git fetch" to retrieve it.
hint: 
hint: If you are planning to push out a new local branch that
hint: will track its remote counterpart, you may want to use
hint: "git push -u" to set the upstream config as you push.

我应该如何解决这个错误?我正在使用 Git 2.9.3。

【问题讨论】:

  • 您是否按照提示运行了“git fetch”?还有,你在当地的哪个分公司?
  • @zim 感谢您的建议。我尝试运行git fetch,但运行git branch master --set-upstream-to=upstream/master 时仍然出现相同的错误。我正在尝试遵循here 描述的步骤。
  • 你能显示这两个命令的输出:“git status”和“git remote -v”吗?
  • 不错,看起来不错。在此处查看接受的答案:stackoverflow.com/questions/22080952/…
  • @zim 对不起,我迷路了。当我尝试文档中的下一步 (git fetch upstream master:master) 时,我收到错误消息“致命:拒绝获取非裸存储库的当前分支 refs/heads/master”,这听起来不正确。

标签: git


【解决方案1】:

git fetch upstream master:master:这项工作only when you are not on master。 如果你在master,一个简单的git fetch upstream 就足够了。

然后你可以将你本地的master链接到远程跟踪分支upstream/master(刚刚获取)

git branch -u upstream/master master

然后您可以使用git pull 更新master
同样,如果您不在 master 上,那么是的,git fetch upstream master:master 可以工作。


Luh_ 在 refspec 中还提到了一个错字问题:请参阅“git fetch doesn't fetch all branches”。

【讨论】:

    【解决方案2】:

    我遇到了类似的问题,但是 git fetch 并没有解决我的问题。另外,就我而言,我发现git config --get remote.origin.fetch 没有返回任何东西while it is suppose to

    我的问题是在相应远程块的 fetch 行中的 .git/config 文件中有错字(可能是我之前错误添加的内容)。因此,请检查您在.git/config file 中的远程输入是否正确,例如:

    [remote "origin"]
        url = https://[server]/[user or organization]/[repo].git
        fetch = +refs/heads/*:refs/remotes/origin/*
    

    你也可以直接remove and re-add the remote entry

    【讨论】:

      【解决方案3】:

      试试这个

      git branch -u git branch --set-upstream-to=<remote>/<remote branch> branch
      

      【讨论】:

      • 我到处都看到这个......你把什么放在 真的没有帮助。
      猜你喜欢
      • 2013-03-14
      • 1970-01-01
      • 2019-11-16
      • 2012-03-21
      • 1970-01-01
      • 1970-01-01
      • 2020-09-16
      • 2019-03-03
      • 2021-07-28
      相关资源
      最近更新 更多