How to sync a git repo to a mirrored repo
Asked Answered
F

5

10

I want to mirror a git repo to my local repo, and wish to timely sync them, I did like this:

git clone --mirror source_url source_repo
cd source_repo
git push --mirror local_url

Now I have mirrored the source repo to my local repo, I could clone my local repo like this:

git clone local_url local_repo

But since the source repo is going update, how could I keep them sync?

Foretooth answered 2/1, 2018 at 2:55 Comment(0)
A
3

Any local repository, either mirrored or working, can be synced with git remote update

cd REPO
git remote update
Anachronistic answered 2/1, 2018 at 7:24 Comment(0)
F
2

There are several approaches here. You can select one that is convenient to you.

  1. The approaches discussed in https://softwareengineering.stackexchange.com/questions/195456/keeping-git-repositories-on-different-hosts-in-sync (writing scripts, etc)
  2. Add a custom hook to your git repo - https://www.digitalocean.com/community/tutorials/how-to-use-git-hooks-to-automate-development-and-deployment-tasks
  3. If you are using a 3rd party tool like BitBucket, they should have built in solutions or plugins for this. Ex : https://marketplace.atlassian.com/plugins/com.englishtown.stash-hook-mirror/server/overview
Forestaysail answered 2/1, 2018 at 3:32 Comment(0)
A
2

Exactly for this purpose I created git-sync-mirror.

git-sync-mirror

A simple synchronization container image for git repositories over HTTPS

Features:

  • Authentication with https tokens
  • If needed, use a different HTTPS Proxy for source and destination
  • TLS-Trust On First Use: Seamlessly run this container behind a https scanning proxy
  • Skip certificate checks (don't do that)
  • Configure time to sleep between synchronization attempts

Usage

$ docker run \
   --rm \
   --env SRC_REPO=source \
   --env DST_REPO=destination \
   --env SLEEP_TIME=30s \
   enteee/git-sync-mirror

Note: The container is designed for synchronization over https with supported authentication using access tokens. For example replace source with https://github-user:[email protected]/Enteee/git-sync-mirror.git

Aran answered 5/7, 2019 at 12:22 Comment(0)
P
1

In my case, I wanted to sync two remote repositories(A and B), after pushing from local repository.

Local repository pushes to remote repository "A"
Remote repository "A" pushes to remote repository "B"

To avoid adding always two repositories for each local repository, I have created post-update hook on remote repository "A" with one line of code:

git push --all --force

Now deployment remote repository "B" is always automatically up-to-date with central remote repository "A".

Photoconduction answered 10/7, 2019 at 14:4 Comment(0)
C
0

I have for years used the following scheme:

  • On one remote server (server1) create one or more master git repositories for my distributed clients. All non-local users (on serverX) clone the desired repos locally and push updates to the master.

  • On another remote server (server2) I clone the master repos as mirrors. Then I set a cron job to periodically run "cd REPO; git remote update". That remote server is currently being set up on Digital Ocean and I have scheduled weekly backups on it. In the past I have mirrored the master repos on at least two different remote servers for safety.

Chapter answered 30/7, 2022 at 13:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.