14

the command

git branch --set-upstream-to develop origin/develop

results in the error

fatal: branch 'origin/develop' does not exist

I am not sure what this means other than origin develop does not exist. Does that mean it doesn't exist on the server or on my local machine?

I am a git newbie but I am in the process of setting up my site to handle deployments with git as a means to learn git.

fontno
  • 6,642
  • 6
  • 36
  • 43
Chris
  • 823
  • 2
  • 7
  • 16

4 Answers4

6

origin is the name of a remote, which is just another repo that your repo knows about. You name repos when adding them, ala git remote add somename other/repo/path, and then you can fetch and pull from them, and if they're bare repos, push to them. When you clone a repo, git sets up a remote for you pointing to the one you cloned from, and names it origin by default. origin/develop refers to the develop branch in the origin remote repo.

If you've made a branch locally, you can push it to a particular remote to create it there, and until you've created it there, you can't set it as upstream. In your case, you would do git push origin develop. Then you could set it as upstream, but you can squeeze that operation into the push operation with -u, so git push -u origin develop, which both pushes your branch to origin, and sets up your local branch to track it. Note that push -u was added in git 1.7.0.

Gary Fixler
  • 5,632
  • 2
  • 23
  • 39
4

First make sure you are at develop branch. Then just use git branch --set-upstream-to origin/develop

erkanyildiz
  • 13,044
  • 6
  • 50
  • 73
1

Git defines git branch --set-upstream-to <upstream> [<branchname>].

Here <upstream> specifies the remote branch and [<branchname>] is the local branch name and if you no branch is specified, it defaults to the current branch.

So, it should be git branch --set-upstream-to origin/develop develop

-u is interchangeable with --set-upstream-to

Song Wang
  • 290
  • 2
  • 9
0

TL;DR

You may need to run git fetch <upstream> before running git branch --set-upstream-to <upstream>.


Today I ran into a similar issue while working on a public repo on Github. I cloned the public repo, made changes locally, then realised that I forgot to first fork this repo on GitHub. So I went ahead and forked it now, but I could not set the local branch to track my fork:

# conventionally it's named 'upstream', but it coincides with git terminology
# so for clarity's sake, I'll name it 'source' in this example
git remote rename origin source
git remote add origin <my-fork>

# errors here:
# fatal: the requested upstream branch 'origin' does not exist
git branch --set-upstream-to origin/master

Basically what's happening is that your local repo isn't aware of the branches in origin, and indeed git hints that you may wish to run git fetch first. However a simple git fetch won't do it, since it automatically fetches from the current default remote, which is still source.

So what you actually need to do first is either:

# one time
git fetch origin

or

# also set origin as default remote for fetch
git fetch --set-upstream origin

Then your git branch --set-upstream-to ... should work as expected.

cyqsimon
  • 2,752
  • 2
  • 17
  • 38