how to address Git error "the requested upstream branch 'upstream/master' does not exist"
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41412398/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to address Git error "the requested upstream branch 'upstream/master' does not exist"
提问by d3pd
I am attempting to follow some steps to contribute to a repository on GitHub and one of the steps is not working. The steps are here: https://github.com/wdbm/qTox/blob/master/CONTRIBUTING.md#how-to-open-a-pull-request.
I am attempting to follow some steps to contribute to a repository on GitHub and one of the steps is not working. The steps are here: https://github.com/wdbm/qTox/blob/master/CONTRIBUTING.md#how-to-open-a-pull-request.
I fork the repository on GitHub.
I fork the repository on GitHub.
I clone the repository:
I clone the repository:
git clone https://github.com/<YOUR_USER>/qTox.git
I access the directory of the local repository:
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:
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:
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:
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.
How should I address this error? I am using Git 2.9.3.
回答by VonC
git fetch upstream master:master
: this work only when you are not on master
.
If you are on master
, a simple git fetch upstream
is enough.
git fetch upstream master:master
: this work only when you are not on master
.
If you are on master
, a simple git fetch upstream
is enough.
Then you can link your local master
to the remote tracking branch upstream/master
(which has just been fetched)
Then you can link your local master
to the remote tracking branch upstream/master
(which has just been fetched)
git branch -u upstream/master master
Then you can use git pull
to update master
.
Again, if you are not on master
, then yes, git fetch upstream master:master
will work.
Then you can use git pull
to update master
.
Again, if you are not on master
, then yes, git fetch upstream master:master
will work.
Luh_mentions also a typo issue in the refspec: see "git fetch doesn't fetch all branches".
Luh_mentions also a typo issue in the refspec: see "git fetch doesn't fetch all branches".
回答by Juh_
I had a similar problem, however git fetch
didn't solve my problem. Also, in my case I found that git config --get remote.origin.fetch
didn't return anything while it is suppose to
I had a similar problem, however git fetch
didn't solve my problem. Also, in my case I found that git config --get remote.origin.fetch
didn't return anything while it is suppose to
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). So, check if your remote entry in the .git/config file
is correct, e.g.:
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). So, check if your remote entry in the .git/config file
is correct, e.g.:
[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
You can also directly remove and re-add the remote entry
回答by user8714329
Try this
Try this
git branch -u git branch --set-upstream-to=<remote>/<remote branch> branch