使用两个不同的URL推送到同一个git remote [英] Push to same git remote using two different URLs

查看:77
本文介绍了使用两个不同的URL推送到同一个git remote的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的家庭服务器上有一个裸存储库,我将其从该存储库推送到该存储库 笔记本电脑进行备份.由于使用了新的路由器,我无法从 在我的家庭局域网中使用全局URL到家庭服务器 与"NAT环回"有关),但需要使用本地LAN地址.所以我的 .git/config现在包含用于同一裸仓库的两个远程控制器:

I have a bare repository on my home-server to which I push from my laptop for backup. Due to a new router I cannot push anymore from within my home-LAN to the home-server using the global URL (something to do with "NAT loopback") but need to use the local LAN address. So my .git/config now contains two remotes for the same bare repository:

[remote "home1"]
        url = ssh://username@my.url/home/username/git_bare_repos/repo.git
        mirror = true
[remote "home2"]
        url = ssh://username@192.168.1.74/home/username/git_bare_repos/repo.git
        mirror = true

那么,问题是:可以吗?有潜在的危害/陷阱吗?并且有更好的方法来执行此操作,这样我就不必根据自己是否在家而使用不同的命令了?

So, questions: Is this ok? Are there potential hazards/pitfalls? And is there a better way to do this, so I wouldn't have to use different commands depending on whether I'm at home or not?

推荐答案

没关系.毕竟它们是相同的仓库.

It's ok. They're the same repo after all.

对您来说唯一的不同是,根据您当前的位置,您将不得不从一个遥控器或另一个遥控器上进行推/拉/等操作.

The only difference for you is that depending on your current location you'll have to push/pull/etc from one remote or the other.

Git为每个分支,标签,远程跟踪分支等保留引用.实际上,它们都是对commit的引用,并且它们在.git/refs/...中具有文件表示形式.

Git keeps a reference for every branch, tag, remote-tracking branch, etc. In fact, they are all references to commits, and they have a file representation in .git/refs/....

通过比较这些引用,git知道每个分支,标签等的状态.例如,如果将refs/heads/masterrefs/remotes/origin/master进行比较,并且分支未同步,则这些引用将有所不同.要查找哪个已过期,git可以只验证本地分支中是否存在远程提交,如果存在,则远程分支已过时.这也使git可以告诉您本地分支在远程分支之前的提交次数,反之亦然.

By comparing these references git knows the status of each branch, tag, etc. For example, if you compare refs/heads/master to refs/remotes/origin/master, and the branches are not sync'd, then these refs will differ. To find which one is outdated, git can just verify if the remote commit exists in the local branch, and if it does, then the remote branch is outdated. This also allows git to tell you how many commits your local branch is ahead of the remote branch, and vice-versa.

可以在此处找到更深入的解释.

A more in-depth explanation can be found here.

这篇关于使用两个不同的URL推送到同一个git remote的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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