Skip to content

Scripts

Here’s my personal selection of scripts that you need.

Recursive Git Mirrors

Mirroring git repositories is something we all need to do from time to time. And if not- you’re probably too lazy to do it so you don’t (you should always keep backups)

If you don’t know how to change the push url of a git repository then see this

Here’s a script to mirror every repository in the current folder recursively and in parallel (so you don’t have to wait for each one to finish for the other to start).

bash
cd /home/fluffy/personal/mirrors || exit
mirror_repo() {
repo="${1%/.git}"
echo "Mirroring $repo..."
cd "$repo" || exit
git fetch -p origin
git remote show origin
git push --mirror
cd -
}
export -f mirror_repo
find . -type d -name '*.git' -print0 | parallel -0 mirror_repo

Save the script to a .sh file and thes do a bash filename.sh and it should work.

This script goes through every folder is the /home/fluffy/mirrors directory after which it checks for a .git folder, then fetches the updates from the previous origin (fetch -p), then prints out the new origin ( learn how to set it ) and then finally pushes it (--mirror).