I read a post on LinkedIn about a guy who got suspended from GitHub for unclear reasons, so I did a bit of research and found more cases. Every time it’s the same story: “they accuse me of violating the ToS” / “it’s impossible to talk with anyone” / “the appeal is rejected” and “I’m locked out of my work”.

There is an interesting analysis on this website.
It’s a genuinely scary scenario for people doing my job.
So now I’m adding new mirrors for my code, including the safest mirror I can imagine: my own backup disk!
The playbook to mirror everything
Make a list of all the repos
gh repo list "alros" --limit 1000 --json nameWithOwner -q '.[].nameWithOwner' > repo-list.txt
Create a list of the repos to actually mirror
cp repo-list.txt repo-list-to-mirror.txt
Clean up the trash from repo-list-to-mirror.txt
Save this script in sync-mirror.sh
#!/usr/bin/env bash
set -euo pipefail
MIRROR_DIR="/some/path/for/the/backup"
GH_USER="youruser"
cd "$MIRROR_DIR"
while read -r repo; do
dir="${repo//\//__}.git" # owner/name -> owner__name.git
if [ -d "$dir" ]; then
echo "Updating $repo"
git -C "$dir" remote update --prune
else
echo "Cloning $repo"
gh repo clone "$repo" "$dir" -- --mirror
fi
done
echo "Mirror sync complete: $(date)"
Give it execute permissions
chmod a+x sync-mirror.sh
Start the sync
cat repo-list-to-mirror.txt | ./sync-mirror.sh
Smoke test to verify that the history is there
git -C "/some/path/for/the/backup/owner__repo.git" log --oneline -5 # verify history
Clone and verify the repository
git clone "/some/path/for/the/backup/owner__repo.git" ~/restored-repo # restore a working copy
Afterthoughts
There are 4 levels of repos in my GitHub account:
- The good: public repos that are genuinely useful.
- The bad: public repos with forgotten trash or forks of other people’s repos.
- The ugly: private repos with tools I’m ashamed to share, or terrible trash.
- The wtf: private archived repos that I don’t even want to see anymore!
I should really clean up my account!