Git - 使用多个遥控器来跟踪同一分支和服务器 [英] Git - Using multiple remotes to track the same branch and server

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

问题描述

我试图在我的远程服务器上建立一个Git仓库,我正在与其他人分享。唯一的问题是,这是位于我的局域网中,我并不总是这个局域网的一部分。
我希望能够使用同一分支的2个遥控器,全部同步,几乎像一个符号链接(但与configs)。



如果我尝试在局域网中使用外部IP作为远程设备,则会更加困难,因为它会映射到路由器自身的内部IP。
我希望能够在局域网中执行 git push / pull lan 来推送,而 git push / pull wan 时,不要抱怨,并确保没有抱怨任何有关他们两个是分开的。



我也想确保他们使用相同的数据在它们之间进行同步,因为目标服务器在任何情况下都是相同的。我有一些Git的经验,但还不足以做到这一点,并确保它能够按计划运行。



我不想尝试同时同步通过为一个分支设置两个远程URL,因为它会因为超时而使得推/拉非常慢。假设我已经设置了局域网,是最新的,并且已经有初始提交,并且WAN尚未建立。



假定服务器的内部IP是 myserver。 lan ,外部的是 mydomain.org ,我该怎么做?

解决方案

正如我在下面评论的那样,可以根据需要添加到本地仓库中的许多远程物品:

  git remote add upstream1 / url / first / repo 
git remote add upstream2 / url / first / repo

然后, git push 可以选择正确的远程使用:

  git push upstream1 
#或
git push upstream2






最简单的方法是添加一个脚本,它可以: b
$ b


  • 测试正确的url(with,for例如,git ls-remote / url / to / remote / repo)

  • 将原点替换为当前环境中的url

      git remote set-url origin / url / that / works 




这样,您总是只有一个远程管理器:默认的一个名为' origin '。

但是每次你切换环境时,你的脚本都可以更新 origin url。


I am trying to set up a Git repo on a remote server of mine, that I am sharing with someone else. Only thing is, this is located in my LAN, which I am not always a part of. I would like to be able to have 2 remotes using the same branch, all synchronized, almost like a symlink (but with configs).

To make things harder, if I try to use the external IP as a remote while in the LAN, it will fail, as that maps to my router's own internal IP. I would like to be able to do git push/pull lan to push while in LAN, and git push/pull wan when not, and ensure neither complain about anything relating to the two of them being separate.

I would like to also ensure they use the same data for syncing between them, as the destination server is the same in either case. I have some experience with Git, but not enough to be able to do this and be sure that it will work as planned.

I do not want to try to sync both of them at once by setting 2 remote URLs for the one branch, as it will just make pushing/pulling very slow because of timeouts.

Assume I have set up LAN already, is up to date, and has an initial commit already, and WAN is not yet set up.

Say the server's internal IP is myserver.lan, and the external one is mydomain.org, how would I go about this?

解决方案

As I commented below, one can add to a local repo as many remotes as you need:

git remote add upstream1 /url/first/repo
git remote add upstream2 /url/first/repo

Then a git push can select the right remote to use:

git push upstream1
# or
git push upstream2


The easiest would be add a script which would:

  • test for the right url (with, for instance, git ls-remote /url/to/remote/repo)
  • replace origin with the url that works in the current environment

    git remote set-url origin /url/that/works
    

That way, you always have just one remote to manage: the default one called 'origin'.
But each time you are switching environment, your script can update origin url.

这篇关于Git - 使用多个遥控器来跟踪同一分支和服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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