首页 新闻 会员 周边

git中新建分支后push时的"no upstream branch"问题

0
悬赏园豆:50 [已解决问题] 解决于 2017-07-05 12:30

通过 git checkout -b 命令新建分支后,git push 时会出现下面的错误提示:

# git push 
fatal: The current branch make-scripts-executable has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin make-scripts-executable

只有改用 git push --set-upstream ... 才能push,请问有没有什么设置方法,可以直接 git push 。

git
dudu的主页 dudu | 高人七级 | 园豆:31003
提问于:2017-07-04 16:15
< >
分享
最佳答案
0

在 Why do I need to do `--set-upstream` all the time? 中找到了解决方法:

git config --global push.default current
git push -u
dudu | 高人七级 |园豆:31003 | 2017-07-05 12:29
其他回答(2)
0

直接从本地检出的新分支,第一次push,远程仓库还没有与之建立tracing关系的分支,所以需要设置upstream,这个设置一次之后,后面再push的时候就不用设置了

收获园豆:50
苍枫露雨 | 园豆:1027 (小虾三级) | 2017-07-04 19:23

但每次新建分支都有这个问题

支持(0) 反对(0) dudu | 园豆:31003 (高人七级) | 2017-07-04 20:03

@dudu: 是的,因为你是直接中本地拉的新分支。   你可以尝试从远程分支拉新的分支,例如:

git checkout -b <BRANCH-NAME> <REMOTE-NAME>/<BRANCH-NAME>

 关于push到远程分支你可参考下这篇博客:http://www.cnblogs.com/chrischennx/p/6653774.html

支持(0) 反对(0) 苍枫露雨 | 园豆:1027 (小虾三级) | 2017-07-05 10:01

@苍枫露雨: 使用这个方法会出现下面的错误提示:

fatal: The upstream branch of your current branch does not match
the name of your current branch.  To push to the upstream branch
on the remote, use

    git push origin HEAD:master

To push to the branch of the same name on the remote, use

    git push origin dev-test
支持(0) 反对(0) dudu | 园豆:31003 (高人七级) | 2017-07-05 12:20

@dudu: 你看下你当前的push设置是什么,

git config push.default

或者

git config --global push.default

 

支持(0) 反对(0) 苍枫露雨 | 园豆:1027 (小虾三级) | 2017-07-05 14:17

@dudu: 前面说的博客中有关于push.default的说明:

Git中push.default可以指定在没有明确指定远程分支的情况下,默认push的远程分支,其取值可以是:

  • nothing - push操作无效,除非显式指定远程分支(想让push变得简单的就不要用这个)
  • current - push当前分支到远程同名分支,如果远程同名分支不存在则自动创建同名分支(central 和 non-central workflows都适用)
  • upstream - push当前分支到它的upstream分支上(通常用于central workflow)
  • simple - simple和upstream是相似的(通常用于central workflow),只有一点不同,simple必须保证本地分支和它的远程 upstream分支同名,否则会拒绝push操作
  • matching - push所有本地和远程两端都存在的同名分支

central / non-central workflows 是Git的两种常见工作流场景:

  • central workflows - 集中式工作流,一个分支的push和pull都是同一个远程仓库
  • non-central workflows - 非集中式工作流,一个分支的push和pull可能分别都有不同的远程仓库

在Git 2.0之前,push.default的内建值被设为'matching',2.0之后则被更改为了'simple'。

支持(1) 反对(0) 苍枫露雨 | 园豆:1027 (小虾三级) | 2017-07-05 14:23

@dudu: 默认的设置是simple,本地分支和远程分支名称一样就不会有这个问题了,

支持(0) 反对(0) 苍枫露雨 | 园豆:1027 (小虾三级) | 2017-07-05 14:37

@苍枫露雨: 学习了,我想要的就是current

支持(0) 反对(0) dudu | 园豆:31003 (高人七级) | 2017-07-05 14:53
0

git push --set-upstream origin make-scripts-executable

慧☆星 | 园豆:5640 (大侠五级) | 2017-07-05 09:18
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册