17

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?

17

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.

| improve this answer | |
  • 3
    git push origin test pushes the local test branch to origin/test. Just in case somebody was expecting the current branch to get pushed. – JonnyJD Dec 22 '12 at 17:41
  • Let us say, you want to push to a feature/Calculator branch in your repository and calcFeature is your local branch that you just created. what should be the git command? git push feature/Calculator calcFeature gave a fatal error saying feature/Calculator is not the correct repository – codingbbq Jan 23 '18 at 6:50
  • 1
    @noobcode git push origin calcFeature:feature/Calculator should do the trick IIRC. Alternatively, you could also do git push -u origin feature/Calculator while you have calcFeature checked out – lucidbrot Jan 31 '18 at 20:27
10

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.

| improve this answer | |
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.

| improve this answer | |
1

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

| improve this answer | |
0

git push origin master will push your changes to the remote server. "master" refers to master branch in your repository.

If you want to push your changes to any other branch (say test-branch), you can do it by: git push origin test-branch.

This will push your code to origin of test-branch in your repository.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.