我可以使用git将本地分支映射到具有不同前缀的远程分支吗? [英] Can I map local branches to remote branches with different prefixes in git?

查看:253
本文介绍了我可以使用git将本地分支映射到具有不同前缀的远程分支吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用一个半集中的git存储库,在这里我工作。每个开发人员在中央git存储库中都有自己的子树,因此它看起来像这样:

 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 看起来像这样:

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

 

编辑:我也想应用这个来取/取。但是分支。< name> .merge 处理了这个问题?



我会继续研究如果我找到了某些东西,请在这里发帖,但我希望能找到其他一些好主意。
$ b 编辑2:我决定了我会保持本地和远程分支名称相同。它看起来是最少的工作,也是最不容易发生未来问题的解决方案。

如果可以的话,我建议你使用相同的本地分支名称&远程。然后 git push 会将所有本地分支都推送到中央存储库中的相应分支。



要使用不同的前缀在本地和远程仓库中,每次创建新功能分支时都需要为配置文件添加映射。设置topic / BRANCH_NAME映射的命令是:

  git config remote.origin.push refs / heads / topic / BRANCH_NAME :michael / BRANCH_NAME 


We're working with a semi-centralized git repository here where I work. Each developer has their own subtree in the central git repository, so it looks something like this:

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

Working locally in my tree I have topic/feature, which corresponds to michael/feature in the central tree.

I've been using

git push origin topic/feature:michael/feature

to push my changes to the remote tree. However, this is cumbersome and prone to mistakes (e.g. omitting the developer name, misspelling the feature name, etc.).

I'm looking for a cleaner way to do this. For instance, "git push". I suspect that setting a different remote with a modified fetch refspec will do it, but I'm not sure how exactly to do it. I'm also not sure how to modify my current branch definitions to use the different remote.

My current .git/config looks something like:

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

Edit: I'd also like to apply this to pulls/fetches. But does the branch.<name>.merge take care of that?

I'll continue to research this and post here if I find something, but I'm hoping to get some other good ideas.

Edit 2: I've decided I'll keep local and remote branch names the same. It appears it will be the least work and least prone to future problems.

解决方案

If you can, I suggest you use the same branch names locally & remotely. Then git push will push all of your local branches to corresponding branches in the central repository.

To use different prefixes in local and remote repos, you need to add a mapping to your config file each time you create a new feature branch. The command to set up the mapping for topic/BRANCH_NAME is

 git config remote.origin.push refs/heads/topic/BRANCH_NAME:michael/BRANCH_NAME

这篇关于我可以使用git将本地分支映射到具有不同前缀的远程分支吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆