36

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 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.

6
  • 3
    did you run "git fetch", as the hint says? also, what branch are you in locally?
    – zim
    Commented Dec 31, 2016 at 23:48
  • @zim Thanks for your suggestion. I tried running git fetch, but I still get the same error when I run git branch master --set-upstream-to=upstream/master. I am attempting to following the steps described here.
    – d3pd
    Commented Jan 1, 2017 at 0:16
  • 1
    can you show the output from these two commands: "git status" and "git remote -v"?
    – zim
    Commented Jan 1, 2017 at 0:24
  • 1
    good, that looks rights. check out the accepted answer here: stackoverflow.com/questions/22080952/…
    – zim
    Commented Jan 1, 2017 at 1:01
  • 1
    @zim Sorry, I'm lost. When I try the next step in the documentation (git fetch upstream master:master) I get the error message "fatal: Refusing to fetch into current branch refs/heads/master of non-bare repository" which does not sound right.
    – d3pd
    Commented Jan 1, 2017 at 1:29

4 Answers 4

37

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)

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.


Luh_ mentions also a typo issue in the refspec: see "git fetch doesn't fetch all branches".

2
  • 1
    git fetch upstream was what did it for me on my master branch! I kept doing git fetch, like the hint said, but that did nothing. git's hints could really be a bit more specific(=practical) sometimes. Thank you!
    – K.Sy
    Commented Jun 5, 2023 at 8:31
  • 1
    @MaximizedAction True, the remote name is important in this case. Without it, Git would use by default the name "origin".
    – VonC
    Commented Jun 5, 2023 at 8:49
12

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.:

[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

1
  • 2
    Thanks, after hours trying to fix this error, I dicover that the old developer had left this config wrong
    – renanrider
    Commented Jun 7, 2022 at 19:13
0

Maybe in latest version of git the help text is out-dated.

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'.
1
  • @VonC Do you know how to maybe file a bug with git core or submit a PR yourself? Commented Jun 21, 2022 at 18:08
-6

Try this

git branch -u git branch --set-upstream-to=<remote>/<remote branch> branch
1
  • 1
    I see this everywhere... what do you put for <remote> no help really.
    – Ryan Mann
    Commented Dec 5, 2019 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.