2

I have a strange git scenario: I've been developing on master, and ive noticed that when my CI clones down and attempts to modify a git repository, it doesn't see "master" in the refspec. Thus, the command

git checkout master

Fails. To fix this (as i need my CI to commit some minor updates to master), I tried to do:

git checkout remotes/origin/master

However, that command results in a DETACHED head. The final fix was that, rather than doing a checkout, I do checkout -b like so:

git checkout -b master

Which magically seems to "create" the master branch which (I thought already exists), and then all is right in the world.

My question is, thus: What is the difference between remotes/origin/master and the master created via git checkout -b? Since I only have one remote, I would think they would be synonymous.

jayunit100
  • 17,388
  • 22
  • 92
  • 167

1 Answers1

4

remotes/origin/master is just a remote-tracking branch, it keeps track of which commit the master branch on the remote origin is on. Branches created with git checkout -b <branch> are local branches, not remote-tracking branches. That is the difference.

However, when you clone a repo, a local master is usually created because that is usually the standard default branch from the original repo, unless the original repo is set up to use a different branch name as the default. Perhaps that is why you are able to re-create the master branch locally? You can check by running the following command:

$ git branch -r
  origin/HEAD -> origin/master
  origin/master

In this output, you'll see that origin/HEAD, which represents the default branch on the remote, points to origin/master.

Also, is your CI actually re-cloning the entire repo repeatedly? That seems really inefficient. I think most CI setups would just clone the repo once, and then pull or receive new changes.

  • Thanks, ive set it to reclone every time just to help isolate the cause of this issue, but your right in the next iteration we want to pull changes rather than clone a fresh repo every time. – jayunit100 Mar 19 '14 at 05:51