From 330f0f9253a90976fc6ba5136b0b5fb2a58bb993 Mon Sep 17 00:00:00 2001 From: Lukas Winkler Date: Fri, 30 Dec 2022 15:05:57 +0100 Subject: [PATCH] first version --- .gitignore | 2 ++ README.md | 8 ++++++++ sync.py | 17 +++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 sync.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..793251f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/ +repos diff --git a/README.md b/README.md new file mode 100644 index 0000000..10b8d6a --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# A simple way to mirror git repositories + +```bash +cd repos +git clone --mirror https://source.example +cd repo.git +git remote add --mirror=push target https://target.example +``` diff --git a/sync.py b/sync.py new file mode 100644 index 0000000..f878e9f --- /dev/null +++ b/sync.py @@ -0,0 +1,17 @@ +import subprocess +from pathlib import Path + +current_dir = Path(__file__).parent + +repo_dir = current_dir / "repos" + +source_remote_name = "origin" +target_remote_name = "target" + +for dir in repo_dir.glob("*"): + print(dir) + print("pull") + subprocess.run(["git", "remote", "update", source_remote_name], check=True, cwd=dir) + print("push") + subprocess.run(["git", "push", target_remote_name], check=True, cwd=dir) + # --mirror is implicit due to remote config