Skip to content

Instantly share code, notes, and snippets.

@mijdavis2
Last active May 22, 2021 14:14
Show Gist options
  • Save mijdavis2/bdd1c30905dad8302cdb490b5687297a to your computer and use it in GitHub Desktop.
Save mijdavis2/bdd1c30905dad8302cdb490b5687297a to your computer and use it in GitHub Desktop.
Clone all repos from org or user via gh cli (GitHub cli)
#!/bin/bash
#
# Requires `gh` --> https://cli.github.com/
#
# Ensure you setup gh cli via `gh auth login`
# and select the `ssh` option if you are cloning private repos - much easier.
#
# Usage:
# $ ./clone-repos.sh some_org target_dir
# Cloning into 'target_dir/some_repo'...
#
gh repo list "$1" --limit 1000 | while read -r repo _; do
repo_name=$(echo "$repo" | grep -oP "^$1\K.*")
gh repo clone "$repo" "$2$repo_name"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment