Skip to content

Instantly share code, notes, and snippets.

@xero
Last active July 3, 2024 02:31
Show Gist options
  • Save xero/9a293b2059d86a0557a575131c7f853f to your computer and use it in GitHub Desktop.
Save xero/9a293b2059d86a0557a575131c7f853f to your computer and use it in GitHub Desktop.
sync github repos to bare repositories on a local machine, as well as multiple remote mirrors (run as a cron job!)
#!/bin/bash
#shellcheck disable=SC2164
#
# sync multiple github repos to bare repositories on
# a local machine, as well as multiple remote mirrors
#
# ▓▓▓▓▓▓▓▓▓▓
# ░▓ author ▓ xero <[email protected]>
# ░▓ code ▓ https://code.x-e.ro
# ░▓ mirror ▓ https://github.com/xero
# ░▓▓▓▓▓▓▓▓▓▓
# ░░░░░░░░░░
sync() {
cd "$TMP"
echo "cloning $1"
git clone --quiet "[email protected]:user/$1" "$1" && cd "$1"
# add a local bare remote
git remote add local "/path/to/your/gitserver/$1"
# add more remotes
git remote add gitlab "[email protected]:user/$1"
git remote add srchut "[email protected]:~user/${1%%.*}"
# push all the things! \o/
git remote | xargs -L1 git push --all
# optional
last=$(git log -1 --format="%at")
mysql --execute="update code set updated = '$last' where repo = '$1';"
}
# clean up after yourself
selfdestruct() {
err=$?
trap '' EXIT HUP INT QUIT PIPE TERM
[[ -d "$TMP" ]] && rm -rf "$TMP"
exit $err
}
trap selfdestruct EXIT HUP INT QUIT PIPE TERM
TMP=$(mktemp -d -t git-XXXXXXXXXX)
# repo list
declare -a repos=(
"hypermedia-blog.git"
"superGarlicboy.git"
"dotfiles.git"
"figlet-fonts.git"
"miasma.nvim.git"
"sofancy.git"
"moebius-web.git"
"0.xxe.ro.git"
"glitchlock.git"
"pgp-suffix-finder.git"
"sourcerer.git"
"blaquemagick.vim.git"
"startpage.git"
)
# main loop
for r in "${repos[@]}"; do sync "$r"; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment