Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

git-remote

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?

like image 492
John Rumpel Avatar asked May 14 '12 17:05

John Rumpel


People also ask

What is the difference between origin master and origin master?

Master: This is a branch name where we first initiate git and then we use to make commits. And the changes in the master can pull/push into a remote. origin/master: This is a remote branch, which has a local branch named master on a remote named origin.

What is the difference between master and origin in git?

The term "git origin master" is used in the context of a remote repository. It is used to deal with the remote repository. The term origin comes from where repository original situated and master stands for the main branch.

Is origin master a remote?

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

What is the difference between origin and remote in git?

A remote is just a word: a name to use to identify some other Git repository somewhere. The string origin is the default name of the (singular) remote that git clone puts in automatically, when you clone from some other ("origin"-al) Git repository. You can choose some other name, and/or add more remotes.


1 Answers

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.

like image 118
larsks Avatar answered Sep 28 '22 06:09

larsks