[英]how to address Git error "the requested upstream branch 'upstream/master' does not exist"
I am attempting to follow some steps to contribute to a repository on GitHub and one of the steps is not working.我正在尝试按照一些步骤为 GitHub 上的存储库做出贡献,但其中一个步骤不起作用。 The steps are here: https://github.com/wdbm/qTox/blob/master/CONTRIBUTING.md#how-to-open-a-pull-request .步骤在这里: https ://github.com/wdbm/qTox/blob/master/CONTRIBUTING.md#how-to-open-a-pull-request。
I fork the repository on GitHub.我在 GitHub 上 fork 存储库。
I clone the repository:我克隆存储库:
git clone https://github.com/<YOUR_USER>/qTox.git
I access the directory of the local repository:我访问本地存储库的目录:
cd qTox
I add the upstream remote in order to be able to fetch from the upstream repository:我添加了上游远程,以便能够从上游存储库中获取:
git remote add upstream https://github.com/qTox/qTox.git
I attempt to point the local master branch to the upstream repository:我尝试将本地主分支指向上游存储库:
git branch master --set-upstream-to=upstream/master
This command fails with the following error message:此命令失败并显示以下错误消息:
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.
How should I address this error?我应该如何解决这个错误? I am using Git 2.9.3.我正在使用 Git 2.9.3。
git fetch upstream master:master
: this work only when you are not on master
. git fetch upstream master:master
:仅当您不在master
时才有效。 If you are on master
, a simple git fetch upstream
is enough.如果你在master
上,一个简单的git fetch upstream
就足够了。
Then you can link your local master
to the remote tracking branch upstream/master
(which has just been fetched)然后您可以将本地master
链接到远程跟踪分支upstream/master
(刚刚获取)
git branch -u upstream/master master
Then you can use git pull
to update master
.然后你可以使用git pull
来更新master
。
Again, if you are not on master
, then yes, git fetch upstream master:master
will work.同样,如果您不在master
上,那么是的, git fetch upstream master:master
将起作用。
Luh_ mentions also a typo issue in the refspec: see " git fetch doesn't fetch all branches ". Luh_在 refspec 中还提到了一个错字问题:请参阅“ git fetch doesn't fetch all branches ”。
I had a similar problem, however git fetch
didn't solve my problem.我有一个类似的问题,但是git fetch
并没有解决我的问题。 Also, in my case I found that git config --get remote.origin.fetch
didn't return anything while it is suppose to另外,在我的情况下,我发现git config --get remote.origin.fetch
没有返回任何东西,而它应该是
My problem was that there was a typo in the .git/config
file in the fetch line of the respective remote block (probably something I added by mistake previously).我的问题是相应远程块的 fetch 行中的.git/config
文件中有错字(可能是我之前错误添加的内容)。 So, check if your remote entry in the .git/config file
is correct, eg:因此,请检查.git/config file
中的远程条目是否正确,例如:
[remote "origin"]
url = https://[server]/[user or organization]/[repo].git
fetch = +refs/heads/*:refs/remotes/origin/*
You can also directly remove and re-add the remote entry您也可以直接删除并重新添加远程条目
I had a similar problem, however git fetch
didn't solve my problem. 我有一个类似的问题,但是git fetch
无法解决我的问题。 Also, in my case I found that git config --get remote.origin.fetch
didn't return anything while it is suppose to 另外,在我的情况下,我发现git config --get remote.origin.fetch
在假定为
My problem was that there was a typo in the .git/config
file in the fetch line of the respective remote block (probably something I added by mistake previously). 我的问题是,在相应远程块的访存行的.git/config
文件中有一个错字(可能是我之前错误添加的内容)。 So, check if your remote entry in the .git/config file
is correct, eg: 因此,请检查.git/config file
中的远程条目是否正确,例如:
[remote "origin"]
url = https://[server]/[user or organization]/[repo].git
fetch = +refs/heads/*:refs/remotes/origin/*
You can also directly remove and re-add the remote entry 您也可以直接删除并重新添加远程条目
Maybe in latest version of git the help text is out-dated.也许在最新版本的 git 中,帮助文本已经过时了。
I was running into this:我遇到了这个:
$ git pull origin master
From github.com:TextUsBiz/tesseract
* branch master -> FETCH_HEAD
Already up to date.
$ git branch --set-upstream-to=origin/master master
fatal: the requested upstream branch 'origin/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.
hint: Disable this message with "git config advice.setUpstreamFailure false"
I thought the error message was quite odd, but.. I tried this, and it worked!我认为错误消息很奇怪,但是..我试过了,它奏效了!
$ git branch --set-upstream-to=master master
branch 'master' set up to track 'origin/master'.
尝试这个
git branch -u git branch --set-upstream-to=<remote>/<remote branch> branch
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.