In Git, What Is the Difference Between Origin/Master vs Origin Master?

I know, 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

7 Answers

(Note: When this question was originally posted, "master" was the default name for branches in Git. Since "main" is now the default name, this answer has been updated to use "main", in the hope that this will be more natural for people new to Git.)

There are actually three things here: origin main is two separate things, and origin/main is one thing. Three things total.

Two branches:

  • main is a local branch
  • origin/main is a remote tracking branch (which is a local copy of the branch named "main" on the remote named "origin")

One remote:

  • origin is a remote

Is origin/main remote?

The origin/main branch is local! Any time you fetch from origin, origin/main will get updated. However, origin/main can be out of date, and it's even possible that main no longer exists on origin. You can use the --prune option (-p) with git fetch to automatically delete remote tracking branches if the branch they track is deleted.

The origin/main branch is not a reference or pointer to the main branch on origin. It is a local copy.

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.