Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is "refs/heads/master" same as "refs/remotes/origin/master" in Git?

Tags:

git

The question is simple: is refs/heads/master the same thing as refs/remotes/origin/master? If it is not in some cases, how can I know when it is not and what it is then?

like image 994
Tower Avatar asked Sep 24 '11 18:09

Tower


People also ask

What is the difference between origin master and 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 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.

What is remotes origin head?

What is Origin (or Remote Head) in Git? The word origin is an alias that Git created to replace the remote URL of a remote repository. It represents the default branch on a remote and is a local ref representing a local copy of the HEAD in the remote repository.

What is origin master in git?

Origin and Master are two different terminologies used when working and managing the git projects. Origin is the name used for the remote repository. Master is the name of the branch.


2 Answers

They are two different symbolic names that can point to different things. refs/heads/master is a branch in your working copy named master. Frequently that is a tracking branch of refs/remotes/origin/master because origin is the default name for the remote created by git clone and its primary branch is usually also named master.

You can see the difference between them with git rev-list refs/heads/master..refs/remotes/origin/master which will be empty if they are the same and will otherwise list the commits between them.

like image 167
Ben Jackson Avatar answered Sep 18 '22 18:09

Ben Jackson


The key difference to understand is that the branches under refs/heads/ are branches that, when you have one checked out, you can advance by creating new commits. Those under refs/remotes/, however, are so-called "remote-tracking branches" - these refs just point to the commit that a remote repository was at the last time you did a git fetch <name-of-remote>, or a successful git push to the corresponding branch in that remote repository. (I wrote a blog post that talks about this difference at some length here.)

like image 28
Mark Longair Avatar answered Sep 21 '22 18:09

Mark Longair