What does "master" mean in "git push origin master"

I'm new to git as a version control system. I tried reading the documentation, but I don't understand what "master" means in this command:

git push origin master

Can someone explain in very dumbed-down terms?


Solution 1:

This is the Master branch. The main tree of your control system.

push = push your changes to the remote server
origin = remote Server origin
master = Master branch

If you have another remote branches you have something like "git push origin test" then you push your changes to the test remote branch.

Solution 2:

That master is the <src> part of a refspec.

This means that your local master branch will be pushed to the master branch of the remote origin (orgin/master).


If you would have specified

git push origin master:my_work

then you would have pushed your local master to origin/my_work. If you don't use the :my_work part, then the destination defaults to the same branch as given as source.


Just specifying

git push origin

will push every local branch that has a matching remote branch to that branch per default. Not just the current branch. This is the same as using git push origin :.

You can change this default with git config remote.origin.push HEAD, which would push the current branch to a remote branch with the same name.

See configure-a-local-branch-for-push-to-specific-branch for further details on configuring refspecs and setting push.default.

Solution 3:

Let me try to explain all elements of this command "in very dumbed-down terms".

git push origin master
  1. git you do something with git :)
  2. push you upload your changes to a remote repo = you update the remote repo with your changes
  3. origin you specify the remote place to push to, usually the particular remote repo where you cloned your directory from
  4. master you specify the branch which you want to push to origin

As a newbie you usually will have only one remote repo (origin) and only one branch (master), so you can use:

git push

simply which means the same as git push origin master in this case.

Check also .git/config in your working directory, it contains info on origin and master.

Solution 4:

git push origin master

  • The repository is created in GitHub. So it is the origin. So basically our remote repository(or repo on GitHub is know as origin)

  • Master is nothing but a default branch in our local repo

  • Pushing the local master branch to the remote origin is what makes that command

git push -u origin master

  • -u stand for upstream

  • Using -u is like setting a path for push

  • So next time we can use 'git push' directly, because now we have set a path for where this push should take the current branch to