git push -u是什么意思?

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

在文档中,-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.

什么是上游分支?

142310 次浏览

“上游”指的是其他人将从中提取的主回购,例如你的GitHub回购。-u选项自动为您设置上游,将您的回购链接到中央回购。这样,将来Git“知道”你想要推到哪里,想要从哪里拉到哪里,所以你可以不带参数地使用git pullgit 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.

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

在这之后,你可以输入一个更短的命令: 在git < / >强推

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