Git branching: master vs. origin/master vs. remotes/origin/master

a1232345發表於2015-07-15

I think I'm on the right track to understand the basic concepts of git.

I've already set up and cloned a remote repository. I also created a server side empty repository, and linked my local repository to it.

My problem is that I don't understand the difference between:

  • origin/master vs. remotes/origin/master

As far as I have understood, master is a local branch, and remotes/origin/master is a remote one.

But what exactly is origin/master?

shareimprove this question
 
 
@ChristopherWallace: You provoked two questions on meta with your edit: "Do we really need an [origin] tag?" and "What is the true [Master]?". –  Deduplicator Jul 1 at 17:19
 
@Deduplicator Is that a problem? –  nbro Jul 1 at 18:52
 
@ChristopherWallace: Well, many seem to think both tags (the one you created and the one you just added) are bad. I happen to concurr, but perhaps you have something to add to the discussion linked which wasn't considered. If not, seems so. –  Deduplicator Jul 2 at 12:52

4 Answers

up vote79down voteaccepted

Take a clone of a remote repository and run git branch -a (to show all the branches git knows about). It will probably look something like this:

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

Here, master is a branch in the local repository. remotes/origin/master is a branch named master on the remote named origin. You can refer to this as either origin/master, as in:

git diff origin/master..master

You can also refer to it as remotes/origin/master:

git diff remotes/origin/master..master

These are just two different ways of referring to the same thing (incidentally, both of these commands mean "show me the changes between the remote master branch and my master branch).

remotes/origin/HEAD is the default branch for the remote named origin. This lets you simply say origin instead of origin/master.

相關文章