9

I tried to execute command:

$ git branch --set-upstream-to master origin/master
fatal: branch 'origin/master' does not exist

I checked origin/master exists

Sergii Bezgin
  • 91
  • 1
  • 1
  • 4
  • 1
    `origin/master` is a "remote branch", and remote branches do not *have* "upstreams". Normally they *are* upstreams; normally you'd set `master` (a local branch) to have `origin/master` (remote branch) as its upstream. Is that what you meant to do? – torek Oct 09 '14 at 15:04

3 Answers3

7

The syntax for git branch is:

git branch' (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>]

In your case:

git branch --set-upstream-to=origin/master master 
# or
git branch -u origin/master master

# for git older than 1.8
git branch master --set-upstream origin/master

If you see an error like:

Error is: fatal: 
Cannot setup tracking information; starting point 'origin/master' is not a branch.

It means you haven't fetched anything from the remote origin.

  1. Check that you do have a remote named origin, with a proper associated url

    git remote -v
    
  2. Try and fetch from origin

    git fetch origin
    

You can see more about the fetch process in "After git update remote the new upstream branches are visible but not origin".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
4

Usually after doing a git init and then also creating a repository in Github, the next thing I want to do is set my remote origin and tie my remote branch to my local master branch.

git init
git remote add origin <repository_url>
git fetch

Now, when I enter

 git branch --set-upstream-to=origin/master master

I get the error: fatal: branch 'master' does not exist

So, I did a

git branch -a 

and found only

remotes/origin/master

Since I was in a newly created git repository, I did a simple

git checkout master

After this, git branch -a showed me the local master branch along with the remote,

  • master

    remotes/origin/master

After this

git branch --set-upstream-to=origin/master master

gave no error and my local master branch was set to track the remote master branch.

0

I found this question while searching for

"fatal: branch 'integration/release/February' does not exist"

but the reason for the error in my case was different.

I "set upstream" enough that I'd made a bash alias for it, but when I tried to use the alias I introduced a space that meant the command I was sending was

git branch --set-upstream-to= integration/release/February

whereas what I needed, obviously, was

git branch --set-upstream-to=integration/release/February
Mad Bernard
  • 363
  • 1
  • 7
  • 16