Skip to content

Instantly share code, notes, and snippets.

@jaywcjlove
Created April 23, 2026 02:53
Show Gist options
  • Select an option

  • Save jaywcjlove/59d10d127423430865642256cf502306 to your computer and use it in GitHub Desktop.

Select an option

Save jaywcjlove/59d10d127423430865642256cf502306 to your computer and use it in GitHub Desktop.
Clone all repositories under the GitHub org/user "jaywcjlove" into current directory.
#!/usr/bin/env bash
set -euo pipefail
# Clone all repositories under the GitHub org/user "jaywcjlove" into current directory.
# Usage:
# bash clone-jaywcjlove-repos.sh
# Optional env:
# GITHUB_TOKEN=xxx # raise GitHub API rate limit
# ORG=jaywcjlove # override org/user name
# PER_PAGE=100 # API page size (max 100)
ORG="${ORG:-jaywcjlove}"
PER_PAGE="${PER_PAGE:-100}"
PAGE=1
api_base="https://api.github.com"
api_url="${api_base}/users/${ORG}/repos"
headers=("Accept: application/vnd.github+json")
if [[ -n "${GITHUB_TOKEN:-}" ]]; then
headers+=("Authorization: Bearer ${GITHUB_TOKEN}")
fi
get_clone_urls() {
local json="$1"
if command -v jq >/dev/null 2>&1; then
jq -r '.[].clone_url' <<<"$json"
elif command -v python3 >/dev/null 2>&1; then
python3 - <<'PY' <<<"$json"
import json, sys
items = json.load(sys.stdin)
for it in items:
url = it.get("clone_url")
if url:
print(url)
PY
else
echo "Error: need jq or python3 to parse GitHub API JSON." >&2
exit 1
fi
}
while :; do
response="$(curl -fsSL \
-H "${headers[0]}" \
${headers[1]:+ -H "${headers[1]}"} \
"${api_url}?per_page=${PER_PAGE}&page=${PAGE}&type=all")"
clone_urls="$(get_clone_urls "$response")"
# Empty page => done.
if [[ -z "${clone_urls}" ]]; then
break
fi
while IFS= read -r repo_url; do
[[ -z "$repo_url" ]] && continue
repo_name="${repo_url##*/}"
repo_name="${repo_name%.git}"
if [[ -d "$repo_name/.git" ]]; then
echo "Skip existing: $repo_name"
continue
fi
echo "Cloning: $repo_url"
git clone "$repo_url"
done <<<"$clone_urls"
PAGE=$((PAGE + 1))
done
echo "Done. All repositories under '${ORG}' have been processed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment