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

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

branch.<name>.merge

在git配置中。该变量描述如下:

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

什么是上游分支?


当前回答

“上游”指的是其他人将从中提取的主回购,例如你的GitHub回购。-u选项自动为您设置上游,将您的回购链接到中央回购。这样,在将来,Git“知道”你想要推送到哪里,你想要从哪里拉取,所以你可以不带参数地使用Git pull或Git push。接下来,本文将解释并演示这个概念。

其他回答

“上游”指的是其他人将从中提取的主回购,例如你的GitHub回购。-u选项自动为您设置上游,将您的回购链接到中央回购。这样,在将来,Git“知道”你想要推送到哪里,你想要从哪里拉取,所以你可以不带参数地使用Git pull或Git push。接下来,本文将解释并演示这个概念。

这不再是最新的!

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.

对于最新的或成功推送的每个分支,添加upstream(跟踪)引用,用于无参数git-pull和其他命令。所以,在用-u选项推你的本地分支之后,这个本地分支会自动链接到远程分支,你可以不带任何参数地使用git pull。

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

之后,你可以输入一个更短的命令: > git推

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