Skip to content

Instantly share code, notes, and snippets.

@ip2k
Created September 13, 2016 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ip2k/6e1e4a1d6996bdb010b1f420ea3fa6a0 to your computer and use it in GitHub Desktop.
Save ip2k/6e1e4a1d6996bdb010b1f420ea3fa6a0 to your computer and use it in GitHub Desktop.
Mirror git repos via pull. Grabs all commits, tags, branches, etc and only grabs changes once the initial pull-down is complete.
#!/bin/bash
REPO_BASE_URL='ssh://git@repo.example.com:1234/some-project-space'
REPOS='foo bar baz quux'
echo -e "\e[1;95;102mStarted at $(date) \e[0m"
BASEDIR="${PWD}"
for repo in $REPOS; do
dirname="${repo}.git"
echo -e "Now processing \e[1;95m${dirname}\e[0m"
cd ${BASEDIR}
if [[ -d "${dirname}" ]]; then
echo -e "\e[1;32mFound existing git repo\e[0m"
cd "${dirname}"
git remote --verbose update --prune
retval=$?
else
echo -e "\e[1;36mNo existing git repo; will clone.\e[0m"
url="${REPO_BASE_URL}/${dirname}"
mkdir "${dirname}"
cd "${dirname}"
git clone --mirror "${url}" .
retval=$?
fi
[[ $retval > 0 ]] && echo -e "\e[1;41;97mError processing ${dirname}\e[0m"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment