blog icon indicating copy to clipboard operation
blog copied to clipboard

git 技巧之 --set-upstream

Open youngwind opened this issue 10 years ago • 3 comments

下面的情况我们经常遇到:

从develop分支checkout出feature-a分支,干完活之后git push origin feature.假如再次修改的话,还得再次git push origin feature.每次都要打全才能push成功。

但是,其实可以通过 --set-upstream 让remote的某个分支和本地的某个分支关联起来,这样只要git push一下,就会push到对应的远程分支了。

git branch --set-upstream my_branch origin/my_branch

更简单地方法

上面那个命令太长了,老记不住,后来找到一个更简单了。 第一次push的时候:

git push -u origin my_branch

之后就可以直接push和pull了。

youngwind avatar Dec 13 '15 07:12 youngwind

也可以设置好 .gitconfig 里的

[push]
    default = current

在当前分支下直接 git push 就可以了

tonicmuroq avatar Dec 30 '15 06:12 tonicmuroq

可以直接 git push 然后 git 会提示 : git branch --set-upstream my_branch origin/my_branch 复制、黏贴、回车。。。

Rhan2020 avatar Aug 21 '18 10:08 Rhan2020

新版的git 移除了--set-upstream命令

fatal: the '--set-upstream' option is no longer supported. Please use '--track' or '--set-upstream-to' instead.

git version: 2.15.2

imfht avatar Aug 28 '18 03:08 imfht