1

I find it interesting that the remote branch name to be used when pushing back to the remote git repository is named "origin" when it's actually called "master"... Why is this the case?

PandaSurge
  • 370
  • 1
  • 7
  • 18
  • 3
    Actually, it is `origin/master`. – NiVeR May 21 '18 at 21:19
  • 1
    Origin refers to the remote server, not the branch. You can have multiple remotes set up for the same local repository. Origin is the default name for the one that the repo was cloned from. – jfadich May 21 '18 at 21:19
  • 1
    Also worth remembering: the Git on the remote, i.e., the Git that *you* call `origin`, is a Git repository. It has *its own* branches, including *its* `master`. What you call `origin/master` is your Git's way of remembering *their* `master`, which they just call `master`. (They have no name for your `master` as they have no need to remember that you even exist :-) .) – torek May 21 '18 at 21:47

2 Answers2

7

master is the name of a branch. origin is the name of a remote. A remote is a complete git repository that may contain many symbolic branch names; you're generally trying to push your commits from your local master to the remote's - origin/master in this case.

Carl Norum
  • 219,201
  • 40
  • 422
  • 469
3

The main advantage for origin, which reference where to push, is that it is the default name for a remote repository reference.

So your first push of your local master branch should be:

git push -u origin master

(See "Why do I need to explicitly push a new branch?")

But after that, master is linked to origin/master, and a simple git push will be enough, which defaults to git push origin (git push to origin the current branch)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250