Last active
January 20, 2022 00:33
-
-
Save ahmadnassri/3416eedb503ac7805324c895eeed00e1 to your computer and use it in GitHub Desktop.
bulk-clone with gh + jq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
perhaps check the gh repo clone
options: https://cli.github.com/manual/gh_repo_clone
Nice hint, thanks.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Any ideas, how to clone repo per org folder instead of having all clones in one folder.