Skip to content

Instantly share code, notes, and snippets.

@ahmadnassri
Last active January 20, 2022 00:33
Show Gist options
  • Save ahmadnassri/3416eedb503ac7805324c895eeed00e1 to your computer and use it in GitHub Desktop.
Save ahmadnassri/3416eedb503ac7805324c895eeed00e1 to your computer and use it in GitHub Desktop.
bulk-clone with gh + jq
#!/bin/bash
USAGE="Usage: bulk-clone <mine|user|org> [name]"
[[ $# -eq 0 ]] && echo >&2 "missing arguments: ${USAGE}" && exit 1
# set protocol to ssh
gh config set git_protocol ssh -h github.com
# check if gh cli is installed
hash gh 2> /dev/null || { echo >&2 "gh cli not found. https://cli.github.com" && exit 1; }
# check if jq is installed
hash jq 2> /dev/null || { echo >&2 "jq cli not found. https://stedolan.github.io/jq/" && exit 1; }
ROUTE=$([ "$1" == "mine" ] && echo "user/repos?affiliation=owner" || echo "${1}s/${2}/repos")
gh api $ROUTE --paginate | jq '.[].full_name' | xargs -L1 gh repo clone
@mkostrikin
Copy link

Any ideas, how to clone repo per org folder instead of having all clones in one folder.

@ahmadnassri
Copy link
Author

perhaps check the gh repo clone options: https://cli.github.com/manual/gh_repo_clone

@mkostrikin
Copy link

Nice hint, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment