Skip to content

Instantly share code, notes, and snippets.

@obar1
Forked from davegallant/gh-clone-org
Created June 18, 2021 13:10
Show Gist options
  • Save obar1/4a2b31631979cddb22e087107661d814 to your computer and use it in GitHub Desktop.
Save obar1/4a2b31631979cddb22e087107661d814 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# This script clones all repos in a GitHub org
# It requires the GH CLI: https://cli.github.com
set -euo pipefail
USAGE="Usage: gh-clone-org <user|org>"
[[ $# -eq 0 ]] && echo >&2 "missing arguments: ${USAGE}" && exit 1
org=$1
limit=1000
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
repos_complete=$((repos_complete + 1))
done
echo "Cloning Complete"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment