如何将多个网址附加到单个git远程? [英] How can I attach multiple urls to a single git remote?

查看:101
本文介绍了如何将多个网址附加到单个git远程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在Windows上通过msysgit和Cygwin的组合使用git。

I'm currently using git on windows through a combination of msysgit and Cygwin.

我有一台笔记本电脑,可以移动很多,所以它不是一个一致的位置。不幸的是,我没有一个一致的名称,因为计算机名称没有在我连接的所有位置上解析,所以我不能只使用计算机名称作为URL的主机(例如,git:/ / compname / repo),所以我必须使用IP地址。

I have a laptop which I move around quite a bit, so it's not on a consistent location. Unfortunately, I don't have a consistent name for it due to the computer name not being resolved on all of the locations I connect to, so I can't just use the computer name as the host for the url (e.g. git://compname/repo), so I have to use the IP address.

是否有一种方法可以添加多个网址以便从特定的远程设备进行访问?我见过

Is there a way I can add multiple urls to pull from for a particular remote? I've seen

git remote set-url --add [--push] <name> <newurl>

作为将多个URL添加到远程的一种方式,我可以在.git中看到更新/ config文件,但git只会尝试使用第一个。

as a way to add multiple URLs to a remote, and I can see the updates in the .git/config file, but git only tries to use the first one.

有没有办法让git尝试使用所有的url?我已经尝试了git fetch和git remote update,但在第一个url之后都没有尝试任何东西。

Is there a way to get git to try to use all of the urls? I've tried both git fetch and git remote update, but neither tries anything after the first url.

请注意,我还没有在linux上试过这个,

Note that I haven't tried this on linux yet, and I can't fix the computer name resolution as this is at work.

推荐答案

我认为您最好的办法是设置您的远程URI指向computername,然后将computername添加到您的主机文件(位于%SystemRoot%\system32\drivers\etc\hosts ):

I think your best best is to set your remote URI to point to computername but then add computername to your hosts file (located at %SystemRoot%\system32\drivers\etc\hosts):

computername    192.168.100.34
# computername    192.168.100.68

然后,您可以为不同的IP地址保留多个条目,并根据需要评论/取消注释。没有更多关于在每个回购基础上更改远程URI的问题,只需在一个位置更新,然后使用computername进行所有回购,因为URI将使用新位置。

Then you can keep multiple entries for the different IP addresses and comment / uncomment them as needed. No more messing about changing the remote URI on a per-repo basis, just update in one place and then all repos using computername as the URI will use the new location.

这篇关于如何将多个网址附加到单个git远程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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