Created
March 23, 2022 09:47
-
-
Save minhnguyenvan95/9166977be52ef676da9378451d26e33d to your computer and use it in GitHub Desktop.
gitlab mirror script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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