git push -u是什么意思?

时间:2011-04-06 04:01:02

标签: git

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

从文档中,-u与变量

相关
branch.<name>.merge
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.

什么是上游分支?

3 个答案:

答案 0 :(得分:338)

“上游”指的是其他人将从中撤出的主要回购,例如你的GitHub回购。 -u选项会自动为您设置上游,将您的仓库链接到中央仓库。这样,在将来,Git“知道”你想要推送到哪里以及你想要从哪里开始,所以你可以使用git pullgit push而无需参数。稍微向下,this article解释并演示了这个概念。

答案 1 :(得分:9)

这已不再是最新的!

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.

答案 2 :(得分:3)

当你第一次推送一个新的分支时,使用: >git push -u origin

之后,您只需键入一个较短的命令: >git push

第一次使用 -u 选项会在您的本地分支上创建一个持久的上游跟踪分支。