Skip to content

Instantly share code, notes, and snippets.

@minhnguyenvan95
Created March 23, 2022 09:47
Show Gist options
  • Select an option

  • Save minhnguyenvan95/9166977be52ef676da9378451d26e33d to your computer and use it in GitHub Desktop.

Select an option

Save minhnguyenvan95/9166977be52ef676da9378451d26e33d to your computer and use it in GitHub Desktop.
gitlab mirror script
# fetch all branches # From: http://stackoverflow.com/questions/10312521/how-to-fetch-all-git-branches
#!/bin/bash
sync_gitlab() {
ORIGIN=$1
MIRROR_REMOTE=$2
WORKDIR=$3
if [[ ! -e $WORKDIR ]]; then
echo "project not exist: cloning mirror"
git clone $ORIGIN --mirror $WORKDIR
git -C $WORKDIR remote add mirror $MIRROR_REMOTE
elif [[ ! -d $WORKDIR ]]; then
echo "project already exist: sync now"
fi
git -C $WORKDIR fetch origin
git -C $WORKDIR push mirror --mirror
}
sync_gitlab "https://gitlab.com/group/project.git" "https://gitlab.example.com/group/project.git" "project.git"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment