Explore Courses Blog Tutorials Interview Questions
+1 vote
in DevOps and Agile by (29.3k points)
edited by

I know, the origin is a term for the remote repository and master is the branch there.

I am purposely omitting the "context" here and I am hoping that the answer should not depend upon the context. So in git command lines, what is the difference between origin/master and origin master. Is there a non-ambiguous way to understand when to use origin/master and when I should use origin master?

2 Answers

+2 votes
by (50.2k points)

Here we need to see the difference between




Origin: This is the name of a remote. A remote in Git is a common repository that all team members use to exchange their changes. In most cases, this will be an origin.

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.

I hope you got the difference between origin master and origin/master.

0 votes
by (5.8k points)

You need to know that
A. origin master is two separate things, master is a local branch and origin is a remote
B. origin/master is one thing, origin/master is a remote branch (which is a local copy of the branch named "master" on the remote named "origin")

Let us understand this with the help of an example: pull in two steps
Since origin/master is a branch, you can merge it. Here's a pull in two steps:
Step one, fetch master from the remote origin. The master branch on origin will be fetched and the local copy will be named origin/master.

$ git fetch origin master

Then you merge origin/master into master.

$ git merge origin/master

Now you are ready to push your new changes in master back to origin:

$ git push origin master

Browse Categories