Skip to content

Instantly share code, notes, and snippets.

@allain
Last active December 18, 2025 15:11
Show Gist options
  • Select an option

  • Save allain/b45c53f71552b25295285a9c29947c28 to your computer and use it in GitHub Desktop.

Select an option

Save allain/b45c53f71552b25295285a9c29947c28 to your computer and use it in GitHub Desktop.
Clone all Github Repos
#!/bin/bash
# Usage
# USERNAME=username ./clone-all-github.sh
# Ensure gh CLI is installed
if ! command -v gh &> /dev/null; then
echo "gh CLI not found."
exit 1
fi
# Ensure USERNAME is set
if [ -z "$USERNAME" ]; then
echo "USERNAME environment variable is not set."
exit 1
fi
# Clone all repositories for the user (including private repos)
echo "Fetching repositories for $USERNAME..."
repos=$(gh repo list "$USERNAME" --limit 1000 --json nameWithOwner --jq '.[].nameWithOwner')
if [ -z "$repos" ]; then
echo "No repositories found or error fetching repos."
exit 1
fi
count=$(echo "$repos" | wc -l)
echo "Found $count repositories."
echo
for repo in $repos; do
repo_name=$(basename "$repo")
if [ -d "$repo_name" ]; then
echo "Updating $repo_name..."
git -C "$repo_name" fetch --all
else
echo "Cloning $repo..."
git clone "[email protected]:$repo.git"
fi
done
echo
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment