如何解决Git错误“请求的上游分支'上游/主'不存在”

时间:2016-12-31 23:43:59

标签: git

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

我在GitHub上分叉存储库。

我克隆了存储库:

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

我访问本地存储库的目录:

cd qTox

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

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

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

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。

3 个答案:

答案 0 :(得分:13)

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将会有效。

答案 1 :(得分:1)

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

我的问题是,.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

答案 2 :(得分:-4)

试试这个

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