diff --git a/README.md b/README.md index 9d4c75fa699cf3349cade1e86092d1b63a9cee20..c72d4ffdb09cd45e32b3a541a205246f2fa7c622 100644 --- a/README.md +++ b/README.md @@ -2,26 +2,19 @@ *No-thrills / uni-directional git mirroring.* -Mirrors a git repository **A** to a repository **B**. +Mirrors all branches in a git repository **A** to a repository **B**. (This solution does not need a post-receive hook on **A**.) ### Usage -Clone the source to a location of your choice. +Clone the source **A** to a location of your choice. ```sh -$ git clone git@gitlab.example.com:path/to/repo.git source_repo +$ git clone --mirror git@gitlab.example.com:path/to/repo.git source_repo ``` -Add the target repository as a remote (make sure you can push to target!). +Run script manually or trigger via cronjob/systemd timer to mirror to repo **B**. ```sh -$ cd source_repo -$ git remote add target git@github.com:target/repo.git -``` - -Trigger script manually or via cronjob/systemd timer. - -```sh -$ ./git-mirror.sh source_repo +$ ./git-mirror.sh source_repo git@github.com:target/repo.git ``` diff --git a/git-mirror.sh b/git-mirror.sh index bad212790a271baac74575a7abd7e75c45c334bc..b9f2796c30508cb549c1796218ff190bc6fc7db8 100755 --- a/git-mirror.sh +++ b/git-mirror.sh @@ -2,13 +2,16 @@ set -e -SOURCE_REPO=$1 +SOURCE_REPO_DIR=$1 +TARGET_REPO=$2 -if [[ ! -d ${SOURCE_REPO}/.git ]]; then - echo Repository ${SOURCE_REPO} not found! +if [[ ! -d ${SOURCE_REPO_DIR}/objects ]]; then + echo Repository ${SOURCE_REPO_DIR} not found! exit -1 fi -cd ${SOURCE_REPO} +cd ${SOURCE_REPO_DIR} + +# get branches in origin git fetch --prune origin -git push --mirror --prune target +git push --prune --mirror ${TARGET_REPO}