Mirror a Repository


I don't know if GitLab / Gitaly will get upset about the files changing under it's feet... I'm trailling this with low-priority projects initially.

First, create the repository via the UI, import an existing project if you wish.

Then, you'll need to modify the Git repositories configuration.

Navigate to https://${GITLAB_URL}/admin/projects/${PROJECT_PATH}, and find the "Gitaly relative path".

Now go to the Git repository on disk (i.e: /path/to/gitlab/repositories/${GITALY_REL_PATH}).

Run the following

git remote add origin ${ORIGIN_URL}
git config remote.origin.fetch "+refs/*:refs/*"
git config remote.origin.mirror true

Subsequently, to update the mirror, run:

git remote update


find /path/to/gitlab/repositories -type d -name '*.git' \
  | while read repo; do \
    [ ! -f "${repo}/config" ] && continue
    grep -qE ' true$' \
      <( GIT_DIR="${repo}" git config --bool --get-regexp 'remote\.([^\.]+)\.mirror' ) \
      || continue
    echo "Updating [${repo}]..."
    GIT_DIR="${repo}" git remote update