git push -u 是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5561295/
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-10 10:33:15  来源:igfitidea点击:

What does git push -u mean?

git

提问by Frankie Ribery

I have two different versions of git. In the 1.6.2 version, git pushdoes not have the -uoption. It only appears in the 1.7.x version.

我有两个不同版本的 git。在1.6.2版本中,git push没有该-u选项。它只出现在 1.7.x 版本中。

From the docs, the -uis related to the variable

从文档中,-u与变量有关

branch.<name>.merge

in git config. This variable is described below:

git config。该变量描述如下:

Defines, together with branch.<name>.remote, the upstream branch 
for the given branch. It tells git fetch/git pull which branch to merge.

What is an upstream branch ?

什么是上游分支?

回答by Rafe Kettler

"Upstream" would refer to the main repo that other people will be pulling from, e.g. your GitHub repo. The -u option automatically sets that upstream for you, linking your repo to a central one. That way, in the future, Git "knows" where you want to push to and where you want to pull from, so you can use git pullor git pushwithout arguments. A little bit down, this articleexplains and demonstrates this concept.

“上游”指的是其他人将从中提取的主要存储库,例如您的 GitHub 存储库。-u 选项会自动为您设置上游,将您的存储库链接到中央存储库。这样,在未来,Git 会“知道”你想推到哪里以及从哪里拉,所以你可以使用git pullgit push不使用参数。稍微往下,这篇文章解释并演示了这个概念。

回答by Peter Piper

This is no longer up-to-date!

这已经不是最新的了!

Push.default is unset; its implicit value has changed in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the traditional behavior, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.

Since Git 2.0, Git defaults to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.