Created
November 15, 2018 10:40
-
-
Save hhromic/23f8cde99ac779e6046c016f9800653b to your computer and use it in GitHub Desktop.
Mirror a git repository into another in Linux
This file contains 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
#!/usr/bin/env bash | |
# Mirror a git repository into another | |
# script by github.com/hhromic | |
# origin git repository | |
declare -r ORIGIN="<<your origin git repository here>>" | |
# destination git repository (mirror) | |
declare -r MIRROR="<<your destination (mirror) git repository here>>" | |
# terminal color settings | |
declare -r YLW=$(tput setaf 3 2>/dev/null) | |
declare -r MGN=$(tput setaf 5 2>/dev/null) | |
declare -r CYN=$(tput setaf 6 2>/dev/null) | |
declare -r RST=$(tput sgr0 2>/dev/null) | |
# make a temporary directory for mirroring | |
echo "${YLW}Creating temporary working directory ...${RST}" | |
TMPDIR=$(mktemp -d) || exit | |
# clone origin, add mirror as remote and synchronise in mirror | |
echo "${YLW}Mirroring '${MGN}${ORIGIN}${YLW}' into '${CYN}${MIRROR}${YLW}' ...${RST}" | |
git clone --mirror "$ORIGIN" "$TMPDIR" || exit | |
git --git-dir "$TMPDIR" remote add --mirror=push mirror "$MIRROR" || exit | |
git --git-dir "$TMPDIR" fetch --prune origin || exit | |
git --git-dir "$TMPDIR" push --mirror mirror || exit | |
# clean temporary directory | |
echo "${YLW}Cleaning temporary directory ...${RST}" | |
rm -rf "$TMPDIR" || exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment