25

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.

Kara
  • 5,996
  • 16
  • 49
  • 56
d3pd
  • 7,237
  • 22
  • 68
  • 120
  • 3
    did you run "git fetch", as the hint says? also, what branch are you in locally? – zim Dec 31 '16 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](https://github.com/wdbm/qTox/blob/master/CONTRIBUTING.md#how-to-open-a-pull-request). – d3pd Jan 01 '17 at 00:16
  • 1
    can you show the output from these two commands: "git status" and "git remote -v"? – zim Jan 01 '17 at 00:24
  • @zim `git status` shows "On branch master Your branch is up-to-date with 'origin/master'." and `git remote -v` shows origin (both fetch and push) as `https://github.com//qTox.git` and upstream (both fetch and push) as `https://github.com/qTox/qTox.git`. – d3pd Jan 01 '17 at 00:55
  • 1
    good, that looks rights. check out the accepted answer here: http://stackoverflow.com/questions/22080952/git-creating-a-branch-which-will-be-pushed-to-a-remote-later – zim Jan 01 '17 at 01: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 Jan 01 '17 at 01:29

3 Answers3

28

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

VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755
6

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

Juh_
  • 13,303
  • 7
  • 53
  • 84
-7

Try this

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