Branch does not exist

Chris picture Chris · May 12, 2013 · Viewed 18.5k times · Source

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.

Answer

Gary Fixler picture Gary Fixler · May 12, 2013

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.