Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two-way git mirror

Tags:

git

I'm interested in setting up a local git repo to be a mirror of a remote repo. I've read a few potentially related posts, however the key difference is that I need read-write access on both repos.

Most of the time, users will work against Repo A, however there will be times when they're working against Repo B, and these need to stay in sync via server-to-server traffic.

What's the best approach here?

As it may complicate the situation, I'll add a note. The ideal way in this environment for devs to switch between master repos is to change the IP address of the repo via /etc/hosts - e.g. Repo A is called "gitserver" when in the office and Repo B is called "gitserver" when remote.

like image 560
Phil Lello Avatar asked Nov 23 '22 15:11

Phil Lello


1 Answers

(Disclaimer: I know this question posting is 7 years old, but it appeared at the top of my StackOverflow question list for reasons I don't know)

I'm interested in setting up a local git repo to be a mirror of a remote repo.

okay...

I've read a few potentially related posts

what posts?

however the key difference is that I need read-write access on both repos

why wouldn't you already have read/write access to both repos? Please don't confuse git with Git-hosting services like GitHub, and be aware that git does not have any built-in permissions system - security is provided by your "git server" and the infrastructure that uses - and there are a wide variety of git server products around (from on-prem GitHub Enterprise and Microsoft Team Foundation Server, to the default in-box gitserver which usually runs behind SSH (and it's SSH that handles authx for you). You can also host a git repo over SMB (aka Windows File Sharing).

Most of the time, users will work against Repo A, however there will be times when they're working against Repo B, and these need to stay in sync via server-to-server traffic.

As a preface, remember that git is a decentralised system that doesn't have to have any canonical repos.

I assume you mean that users will be working against RepoA and RepoB concurrently (rather than everyone using only RepoA on some days, and then only RepoB on other days). In which case just having a cron job to fetch every few minutes and a push hook every time a new branch is updated would work.

What's the best approach here?

Hard to give specifics as there's still a lot of detail you're not giving us (e.g. how do these two hosts communicate? Is a horrible VPN client/system required or do they communicate over the open Internet? Have you considered using a commercial git hosting service like GitHub and GitLab to use as an in-between? Etc?

The ideal way in this environment for devs to switch between master repos is to change the IP address of the repo via /etc/hosts - e.g. Repo A is called "gitserver" when in the office and Repo B is called "gitserver" when remote.

Ack. No. Don't do that! Have your users add both repos as separate remotes to their local repos and give them a little shell-script or macro that converts git push into pushes to all currently available repos.

...your devs do have local (on-computer) repos, right? I hope you're not using a centrally hosted git repo in some kind of multi-user mode? If so, then you're using git very, very wrong.

like image 146
Dai Avatar answered Jan 31 '23 22:01

Dai