“git push”和“git push origin master”有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29858663/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:56:21  来源:igfitidea点击:

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

gitgithubgit-push

提问by Ka-Wa Yip

After a git commit, I have two options:

在 a 之后git commit,我有两个选择:

  1. git push
  2. git push origin master
  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?

我的目的是将我在本地存储库中的更改推送到 GitHub 主分支。他们在什么情况下会有所作为?

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

(另外,这里的“起源”是什么意思?)



[UPDATE]:

[更新]:

I think this is not a duplicate questionwith this post, because, on the mentioned duplicate post, the question about git push originand in this question is about git pushonly.

我认为这不是这篇帖子的重复问题,因为在提到的重复帖子中,关于git push origin和在这个问题中的问题只是关于git push

回答by Makoto

git pushassumes that you already have a remote repositorydefined for that branch. In this case, the default remote originis used.

git push假设您已经为该分支定义了一个远程存储库。在这种情况下,将使用默认遥控器origin

git push origin masterindicates that you are pushing to a specificremote, in this case, origin.

git push origin master表示您正在推送到特定的遥控器,在本例中为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, justyour GitHub repository), then there isn't any difference between the two.

这仅在您在代码库中创建多个远程存储库时才重要。如果您只提交到一个远程存储库(在这种情况下,只是您的 GitHub 存储库),那么两者之间没有任何区别。