29

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.

Benyamin Jafari
  • 27,880
  • 26
  • 135
  • 150
Ka Wa Yip
  • 2,546
  • 3
  • 22
  • 35

1 Answers1

42

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.

Makoto
  • 104,088
  • 27
  • 192
  • 230
  • In addition, doesn't `git push` push all branches, while `git push origin master` only push the master branch? – Oliver Angelil Apr 23 '22 at 05:10
  • @OliverAngelil When you issue the `git push` command, you are doing so from a specific local branch e.g. `master`. So you will be pushing updates in that local branch to the remote repo. I don't think updates from another local branch will be pushed also, In my opinion. – Banty Oct 20 '22 at 15:22