简体   繁体   English

如何设置本地目录以镜像远程git存储库?

[英]How to set up a local directory for mirroring a remote git repository?

Here is the situation. 这是情况。 I have a remote git repository on Server A. Also, I have to work on Desktop B with the same source code in this repository. 我在服务器A上有一个远程git存储库。此外,我必须使用该存储库中的相同源代码在桌面B上工作。 Because of the limited bandwidth to access Server A, I'd like set up a local mirror on Desktop B for the repository. 由于访问服务器A的带宽有限,我想在桌面B上为存储库设置本地镜像。

Now, I have set up the mirror repository by 现在,我通过以下方式建立了镜像存储库

git clone --mirror https://repository-on-server-a /local/repo/path.git

I have tested the local repository by 我已经通过测试了本地存储库

git clone file://localhost/local/repo/path.git

Then I modified crontab to do 然后我修改了crontab做

cd /local/repo/path git fetch -q

to sync up every 5 mins. 每5分钟同步一次。 It works well. 它运作良好。

At the beginning, I was thinking about using 一开始,我正在考虑使用

git config --global url.file://localhost/local/repo/path.git.insteadOf https://repository-on-server-a

to have git fetch all objects from local directory instead of a remote repo. 让git从本地目录而不是远程仓库中获取所有对象。 However, it doesn't work. 但是,它不起作用。

My question is 我的问题是

  1. Is there a simple way to set up such local mirror for a remote git repo? 有没有简单的方法可以为远程git repo设置此类本地镜像?
  2. How to handle 'git push'? 如何处理'git push'? Since the insteadOf will get every push into local directory, how could I push all my changes back to Server A? 由于replaceOf会将所有推送都推送到本地目录,因此如何将所有更改推送回服务器A?

The local directory is for a test but not the final solution. 本地目录用于测试,而不是最终解决方案。 I will have another Desktop C to get source code from Desktop B later. 稍后,我将有另一个桌面C从桌面B获取源代码。 Another colleague will join me too. 另一位同事也将加入我的行列。 That means we want to put all changes in Desktop B to have some 'centric' solution for us. 这意味着我们希望将所有更改都放在Desktop B中,以便为我们提供一些“中心”解决方案。

What's the mirror for? 镜子是做什么用的? Your local git working directory already is a mirror of the origin repository; 您本地的git工作目录已经原始存储库的镜像; that's how DVCSes work. DVCS就是这样工作的。 I don't understand the benefit of a second local copy on your filesystem. 我不了解在文件系统上使用第二个本地副本的好处。

EDIT If you want to use one of your repos as a local-network collection point for changes between the rest of your network and the upstream origin, then the cron job is fine. 编辑如果要使用一个存储库作为本地网络收集点,以在网络的其余部分和上游来源之间进行更改,那么cron作业就可以了。 Just have it do a push --mirror after it does its fetch -a . 在执行fetch -a之后,只需执行push --mirror

However, I wouldn't bother with the proxy/alias setup. 但是,我不会理会代理/别名设置。 Just have everyone clone from and push to your local mirror explicitly; 只是让每个人都克隆并显式推送到您的本地镜像; that way it won't get in the way if they need to get to the real origin for some reason. 这样,如果他们出于某种原因需要到达真正的原点,它就不会成为障碍。 They can even set both URLs as remotes, use the local one by default, and have the real one available by remote name if needed. 他们甚至可以将两个URL都设置为远程URL,默认情况下使用本地URL,并根据需要使用远程名称提供真实URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM