Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between "git push" and "git push origin master"? [duplicate]

After a git commit, I have two options:

  1. git push
  2. git push origin master

My intent is to push my changes in my local repo to GitHub master branch. In what circumstances do they make a difference?

(Also, what does "origin" here mean?)


[UPDATE]:

I think this is not a duplicate question with this post, because, on the mentioned duplicate post, the question about git push origin and in this question is about git push only.

like image 209
Ka-Wa Yip Avatar asked Apr 24 '15 22:04

Ka-Wa Yip


People also ask

What is the difference between git push and git push origin master?

Git Push Origin pushes all the branches to the main branch. Git Push Origin Master pushes your master branch to the origin.

What is difference between git push and git push?

Git push origin is usually used only where there are multiple remote repositories and you want to specify which remote repository should be used for the push. For a git push origin command: git push command updates remote references using local references by sending objects necessary to complete the given references.

What is the difference between origin and master in git?

The term "git origin master" is used in the context of a remote repository. It is used to deal with the remote repository. The term origin comes from where repository original situated and master stands for the main branch. Let's understand both of these terms in detail.

What is difference between origin master and master?

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.


1 Answers

git push assumes that you already have a remote repository defined for that branch. In this case, the default remote origin is used.

git push origin master indicates that you are pushing to a specific remote, in this case, origin.

This would only matter if you created multiple remote repositories in your code base. If you're only committing to one remote repository (in this case, just your GitHub repository), then there isn't any difference between the two.

like image 189
Makoto Avatar answered Oct 14 '22 16:10

Makoto