V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
git
Pro Git
Atlassian Git Tutorial
Pro Git 简体中文翻译
GitX
lululau
V2EX  ›  git

git checkout 之后新的本地分支为什么没有出现在默认 push 的列表里?

  •  
  •   lululau · 2013-09-14 23:31:49 +08:00 · 7509 次点击
    这是一个创建于 3874 天前的主题,其中的信息可能已经有所发展或是发生改变。
    > git checkout -b new_branch remote_name:branch_name
    > git remote show remote_name
    输出:
    remote branches:
    branch_name tracked
    master tracked
    Local branches configured for 'git pull':
    new_branch merges with remote branch_name
    master merges with remote master
    Local ref configured for 'git push':
    master pushes to master (up to date)


    new_branch 怎么没有出现在 Local ref configured for 'git push': 的列表里?
    如果想 new_branch 出现在这个地方应该怎么做?
    7 条回复    1970-01-01 08:00:00 +08:00
    9hills
        1
    9hills  
       2013-09-14 23:54:29 +08:00
    就是这么设计的,因为git鼓励你多开分支,不可能一股脑把几十个本地分支通通push到服务器吧

    如果真需要push,建议单独push,比如你的本地分支名字是develop,只需要

    git push develop origin 就行了
    lululau
        2
    lululau  
    OP
       2013-09-15 00:09:12 +08:00
    @9hills
    我认为不是这样的,因为如果我本地已经有了一个分支“master”(tracking origin/master)创建了一个分支“abc”,我想把它推送到远程服务器,那么执行:
    git push -u origin abc:abc
    那么将在远程服务器上建立一个远程分支:“ origin/abc”。
    这时候执行 git remote show origin ,将会看到:
    ..........
    ..........
    Local ref configured for 'git push':
    master pushes to master (up to date)
    abc pushes to abc (up to date)

    从此之后,当我处于本地分支“master” 时,执行“git push”,将会把本地的“master”分支的提交推送到“origin/master”
    当我处于本地分支“abc”时,执行“git push”,将会把本地的“abc”分支的提交推送到“origin/abc”
    9hills
        3
    9hills  
       2013-09-15 00:20:34 +08:00   ❤️ 1
    @lululau git push 有多种配置

    push.default可以等于
    nothing matching upstream tracking current simple

    而1.7.1之前默认是upstream,之后是simple,不管是两者中的哪一个,按照你的操作流程
    在任何一个分支执行git push后,就会把master和abc的提交都推送到 origin的

    并不是说你要在两个分支分别push一次


    那个git push -u origin abc:abc,如果你的本地分支和服务器分支名字相同,就没必要加冒号以及后面的adb。直接 git push -u origin abc就好了
    9hills
        4
    9hills  
       2013-09-15 00:22:41 +08:00
    @lululau 当然,如果你就是只能push一个,那就要检查这个配置项是不是设置为current了。。

    用git config -l 看下吧
    9hills
        5
    9hills  
       2013-09-15 00:24:22 +08:00
    额,补充一下
    1.7.1之后有了simple选项,但不是默认,默认还是upstream
    2.0才有计划把simple作为默认,取代upstream
    lululau
        6
    lululau  
    OP
       2013-09-15 00:43:29 +08:00
    @9hills 非常感谢,你说的我基本上明白了,是我理解错了。但是还有个问题,我执行了“git config push.default current”,为什么还是不能推送 abc
    9hills
        7
    9hills  
       2013-09-15 00:51:10 +08:00
    @lululau 你设成upstream试试

    current代表只推送本分支,upstream是推送所有有tracking信息的分支,simple 也是推送本分支(不过需要本分支也要有tracking信息,这个我刚才说错了)

    另外 checkout -b 是不能添加tracking信息的,这个是git的设计缺陷,应该试试 --track -b
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5327 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 07:48 · PVG 15:48 · LAX 00:48 · JFK 03:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.