Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is origin/master in git compared to origin master?

Tags:

git

I wanted to add this question as a comment to the answer of @KevinBallard here What's the difference "origin master" vs "origin/master", but my comment was to long.

So my question is: If I am in a branch called topic, is it possible to just write git rebase master instead of git rebase origin/master? Or are there really two different local master branches? One being a copy of the remote master branch and one being my own master branch? If so: When I git pull are both local master branches (one called origin/master and the other just called master) updated? I am very confused …


Or maybe it is like this: origin/master is a local copy of the real remote master branch to which the remote was fetched (copied, i.e. just overwritten), and my local branch called master is only changed, when I git merge origin/master (or git rebase …). That is: When I git pull origin master both my local copy origin/master and master are updated/merged. Of course assuming that I am currently in the master branch (i.e. git checkout master was my last checkout).

like image 879
erik Avatar asked Oct 11 '13 15:10

erik


2 Answers

  • master is your local branch.
  • origin master is the branch master on the remote repository named origin.
  • origin/master is your local copy of origin master.

When you do git pull (what I consider as evil, anyone else?), it automatically does :

  • git fetch : it copies origin master into origin/master. (and all other origin xxx into origin/xxx).
  • git merge : it merges origin/master into master.

When you want to rebase master, you must do :

  • git fetch
  • git rebase origin/master

extract of git help pull:

More precisely, git pull runs git fetch with the given parameters and calls git merge to merge the retrieved branch heads into the current branch

like image 59
Arnaud Denoyelle Avatar answered Oct 12 '22 23:10

Arnaud Denoyelle


<remote>/<branch> named branch are managed automatically by git.

When you do git pull, what git really does is

git fetch  
git merge origin/master

git fetch automatically updates the origin/master local branch to point at the last commit of the origin remote's master branch.

So yes, when you call git pull, both are updated. That's because fetch updates origin/master and merge updates master.

If I am in a branch called topic, is it possible to just write git rebase master instead of git rebase origin/master?

You can, but master is not necessarily the same as origin/master - though most of the time they are. So it is really up to you.

Or are there really two different local master branches?

Yes they are two different local branches. They're just usually pointing to the same commits and share a common tree.

like image 42
Simon Boudrias Avatar answered Oct 12 '22 23:10

Simon Boudrias