Git - 每个分支的不同遥控器 [英] Git - Different Remote for each Branch

查看:93
本文介绍了Git - 每个分支的不同遥控器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定如何正确地提出这个问题,但我会尽力而为 - 我绝不是Git爱好者,我知道如何使用基本命令,但不知道高级术语/功能。

我从私有服务器克隆了一个私有存储库 myrepo git.mydomain.com 。我熟悉使用 git checkout -b mybranch 在同一个存储库上分支代码的过程 - 但是我想分支到GitHub而不是我的私有服务器,在这样的事情:

 回购分行远程位置(目的)
---------- --------------------------------------------------
myrepo - >私人 - > git.mydomain.com(增量工作)
|
+ ------>公开 - > github.com(公开发布)

基本上我希望能够 git checkout public git merge private

解决方案



从Git 1.8.0开始:

您可以设置不同的分支来推送到单个分支的其他分支服务器: / strong>

  git branch -u origin / foo foo 

注意:如果最后一个 foo 被省略,它将选择当前分支。



从Git 1.7.0开始:

  git branch --set-upstream foo origin / foo 

在你的情况下,你可以使用通过添加你的两个遥控器(mydomain和github)并设置每个分支来单独推送它们。它可能看起来像这样:



如果您还没有添加遥控器,请确保您已添加遥控器:

  git remote add github git://github.com/foo/myrepo.git 
git remote add mydomain git://git.mydomain.com/foo/myrepo.git

然后设置分支以推送到正确的地方:

  git branch -u mydomain / private private 
git branch -u github / public public

完成所有设置后,只需使用 git push git拉。当你在公共分支上时,这会推送到github,当你在你的私人分支时,你会到你的mydomain.com。

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.

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)

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:

As of Git 1.8.0:

git branch -u origin/foo foo

Note: If the last foo is left out, it will choose the current branch.

As of Git 1.7.0:

git branch --set-upstream foo origin/foo

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

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屋!

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