Skip to content

Instantly share code, notes, and snippets.

@anilktechie
Forked from ahmadnassri/bulk-clone
Created January 20, 2022 00:33
Show Gist options
  • Select an option

  • Save anilktechie/cf92578e8737f9eece689d274ae2ccfb to your computer and use it in GitHub Desktop.

Select an option

Save anilktechie/cf92578e8737f9eece689d274ae2ccfb 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment