代码之家  ›  专栏  ›  技术社区  ›  Michael Johnson

我可以在git中将本地分支映射到具有不同前缀的远程分支吗?

  •  11
  • Michael Johnson  · 技术社区  · 16 年前

    master
    alice/branch1
    alice/branch2
    bob/branch1
    michael/feature
    release/1.0
    release/1.1

    在我的树中本地工作 topic/feature ,对应于 michael/feature 在中央的树上。

    我一直在用

    git push origin topic/feature:michael/feature
    

    我正在寻找一种更干净的方法来做这件事。例如,” git push “。我怀疑使用修改过的fetch refspec设置不同的远程服务器可以做到这一点,但我不确定具体怎么做。我也不确定如何修改当前的分支定义以使用不同的远程服务器。”。

    我的电流 .git/config 看起来像:

    [remote "origin"]
        url = git://central/git/project
        fetch = +refs/heads/*:refs/remotes/origin/*
    [branch "topic/feature"]
        remote = origin
        merge = refs/heads/michael/project

    编辑: 我还想将此应用于拉/取。但是 branch.<name>.merge 处理好了吗?

    我会继续研究这一点,如果我发现了什么,我会在这里发布,但我希望能得到一些其他的好主意。

    编辑2:

    3 回复  |  直到 12 年前
        1
  •  3
  •   webmat    16 年前

    在[remote“origin”部分中,为每个映射添加一行。包括大师对大师。

    push = refs/heads/master:master
    push = refs/heads/topic/feature:michael/feature
    

    我不知道如何使用gitconfig命令。

    请注意,从现在开始,当您直接执行git推送(没有参数)时,所有分支都会同时被推送。

    您能解释一下为什么不在本地和远程保留相同的分支名称吗?

        2
  •  3
  •   Paul    16 年前

    如果可以,我建议您在本地使用相同的分支名称&远地。然后 git push

    要在本地和远程repo中使用不同的前缀,您需要在每次创建新功能分支时向配置文件添加映射。设置主题/分支名称映射的命令为

     git config remote.origin.push refs/heads/topic/BRANCH_NAME:michael/BRANCH_NAME
    
        3
  •  1
  •   studgeek    12 年前

    git remote add heroku git@heroku.com:YOURAPPNAME.git
    git checkout -b heroku -t heroku/master
    

    请参阅此要点(我做了一些调整),了解适合我的使用步骤 https://gist.github.com/2002048

        4
  •  0
  •   Adwait Mathkari    3 年前

    git branch --set-upstream-to=origin/remoteBranch localBranch
    

    推荐文章