Skip to content

Instantly share code, notes, and snippets.

@WeeJeWel
Created May 16, 2021 17:47
Show Gist options
  • Save WeeJeWel/c84e0bcf5c733b125b365cf0e37e8864 to your computer and use it in GitHub Desktop.
Save WeeJeWel/c84e0bcf5c733b125b365cf0e37e8864 to your computer and use it in GitHub Desktop.
Backup all repositories from a GitHub Organization
#!/bin/bash
# This script backups all repositories in a GitHub Organization
# Required GitHub CLI & Git installed.
ORGANIZATION="athombv"
echo "Backing up $ORGANIZATION...";
gh repo list $ORGANIZATION --limit 99999 > repos.txt
while read line; do
IFS=$'\t'
lineTabSeparated=($line)
repo=$lineTabSeparated;
# If directory exists, update it
if [ -d "./$repo" ]; then
echo "Pulling $repo..."
pwd=$(pwd)
cd $repo
git pull
cd $pwd
# Clone the new repo
else
echo "Cloning $repo..."
gh repo clone "$repo" "./$repo"
fi;
done < repos.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment