`git push`和`git push -u`有什么区别?

时间:2014-06-04 04:00:17

标签: git github

我一直在使用git push -u origin branch一段时间了。 但看到我的同事设法使用git push origin branch推动一个新的分支没有开关你让我思考,有什么主要区别?有没有呢?

1 个答案:

答案 0 :(得分:4)

git help push会告诉你

   -u, --set-upstream
       For every branch that is up to date or successfully pushed, add
       upstream (tracking) reference, used by argument-less git-pull(1)
       and other commands. For more information, see branch.<name>.merge
       in git-config(1).

这意味着,如果您将git push -u some_repo some_branch设置为后续拉动的上游,则运行some_repo/some_branch

因此,下次您some_branch在本地签出并运行git pull时,它会自动尝试从some_repo/some_branch