Code Junkie
Code Junkie

Reputation: 1382

origin/, remotes/origin/ Git confusion

I just cloned a repo and started a new branch in Git. I have done this many times without encountering a problem. Tonight when I tried using git branch --set-upstream develop origin/develop to set the upstream location, I got this error:

fatal: Ambiguous object name: 'origin/develop'.

Reading around suggests that this is a result of the same branch name existing in both the origin, and the remotes/origin. I don't understand the difference between these two, and why they would conflict this way. I typed git branch -a, and this was the output:

* develop
  master
  origin/develop
  remotes/origin/HEAD -> origin/master
  remotes/origin/develop
  remotes/origin/master

I'm confused about what the difference is between origin/develop and remotes/origin/develop, and why that would cause the fatal: Ambiguous object name: 'origin/develop'. error.

Upvotes: 5

Views: 1941

Answers (2)

VonC
VonC

Reputation: 1329562

I confirm origin/develop is the name of a local branch instead of a reference to a remote one (like remotes/origin/develop)

And branches can have a '/' in their name: their are called "hierarchical branch names" (see "Using the slash character in Git branch name").
As explained in this thread, that prevents you to chose "develop" as a branch name. You need to rename it

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

Upvotes: 1

mgarciaisaia
mgarciaisaia

Reputation: 15650

I think that, by mistake maybe, you have a local branch called origin/master. Try running git branch. If there's a origin/master branch listed there, that's it.

See if you should delete that branch. If you can't or don't want to, run git branch --set-upstream develop remotes/origin/develop instead.

Upvotes: 2

Related Questions