Created
November 15, 2018 10:40
-
-
Save hhromic/23f8cde99ac779e6046c016f9800653b to your computer and use it in GitHub Desktop.
Revisions
-
hhromic created this gist
Nov 15, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ #!/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