Git - 每个分支的不同遥控器 [英] Git - Different Remote for each Branch
问题描述
我不确定如何正确提问,但我会尽力而为 - 我绝不是 Git 爱好者,我知道如何使用基本命令但不知道高级术语/功能.
I'm unsure of how to ask this properly but I'll try and do my best - I'm by no means a Git aficionado, I know how to use the basic commands but not advanced terminology/functionality.
我有一个从私有服务器 git.mydomain.com
克隆的私有存储库 myrepo
.我熟悉使用 git checkout -b mybranch
在同一存储库上分支代码的过程 - 但是我想分支到 GitHub 而不是我的私人服务器,结果如下:
I have a private repository myrepo
cloned from a private server git.mydomain.com
. I'm familiar with the process of branching code on the same repository with git checkout -b mybranch
- however I'd like to branch to GitHub rather than my private server, resulting in something like this:
Repo Branch Remote Location (Purpose)
------------------------------------------------------------
myrepo --> private --> git.mydomain.com (Incremental work)
|
+------> public --> github.com (Public releases)
基本上我希望能够git checkout public
和git merge private
.
Essentially I'd like to be able to git checkout public
and git merge private
.
推荐答案
您可以使用以下命令为各个分支设置不同的分支以推送到不同的服务器:
You can set a different branch to push to a different server for individual branches by using these commands:
从 Git 1.8.0 开始:
git branch -u origin/foo foo
注意:如果省略最后一个foo
,则选择当前分支.
Note: If the last foo
is left out, it will choose the current branch.
从 Git 1.7.0 开始:
git branch --set-upstream foo origin/foo
在您的情况下,您可以通过添加两个远程(mydomain 和 github)并将每个分支设置为单独推送到它们来使用它.它可能看起来像这样:
In your case, you would use this by adding your two remotes (mydomain and github) and setting each branch to push to them individually. It might look something like this:
如果您还没有添加遥控器,请确保添加:
Make sure you add the remotes if you haven't already:
git remote add github git://github.com/foo/myrepo.git
git remote add mydomain git://git.mydomain.com/foo/myrepo.git
然后设置分支推到正确的位置:
Then set the branches to push to the right places:
git branch -u mydomain/private private
git branch -u github/public public
这一切都设置好后,你可以使用 git push
和 git pull
来推送和拉取.当您在公共分支上时,这将推拉到 github,当您在私人分支上时,这将推拉到您的 mydomain.com.
After this is all set up, you can push and pull just by using git push
and git pull
. This will push and pull to github when you're on the public branch, and to your mydomain.com when you're on your private branch.
这篇关于Git - 每个分支的不同遥控器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!