Last active
September 28, 2024 04:21
-
-
Save davegallant/277021b86161035e812082e73ae12fb7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# This script clones all repos in a GitHub org | |
# It requires the GH CLI: https://cli.github.com | |
# It can be re-run to collect new repos and pull the latest changes | |
set -euo pipefail | |
USAGE="Usage: gh-clone-org <user|org>" | |
[[ $# -eq 0 ]] && echo >&2 "missing arguments: ${USAGE}" && exit 1 | |
org=$1 | |
limit=9999 | |
repos="$(gh repo list "$org" -L $limit)" | |
repo_total="$(echo "$repos" | wc -l)" | |
repos_complete=0 | |
echo | |
echo "$repos" | while read -r repo; do | |
repo_name="$(echo "$repo" | cut -f1)" | |
echo -ne "\r\e[0K[ $repos_complete / $repo_total ] Cloning $repo_name" | |
gh repo clone "$repo_name" "$repo_name" -- -q 2>/dev/null || ( | |
cd "$repo_name" | |
git pull -q | |
) | |
repos_complete=$((repos_complete + 1)) | |
done | |
echo "Finished cloning all repos in $org." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment