Last active
December 28, 2020 18:02
-
-
Save joemiller/2dd72670e37769cb647c to your computer and use it in GitHub Desktop.
clone all repos from an org, including private repos
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/sh | |
# Reqs: curl, ruby, git | |
# | |
# TOKEN: Create a personal access token here: https://github.com/settings/tokens | |
# | |
# Usage: | |
# | |
# To clone all repos from $ORG into current directory: | |
# | |
# $ curl https://gist.githubusercontent.com/joemiller/2dd72670e37769cb647c/raw | TOKEN=<githubtoken> ORG=<orgname> bash | |
# | |
if [ -z "$TOKEN" ]; then | |
echo "no TOKEN= environment var specified" | |
exit 1 | |
fi | |
if [ -z "$ORG" ]; then | |
echo "no ORG= environment var specified" | |
exit 1 | |
fi | |
echo "==> Cloning all repos from '$ORG'" | |
curl -u "$TOKEN:x-oauth-basic" -s https://api.github.com/orgs/$ORG/repos\?per_page\=500 | ruby -rubygems -e 'require "json"; JSON.load(STDIN.read).each { |repo| %x[git clone #{repo["ssh_url"]} ]}' | |
echo "==> Done." |
Thanks for the script. I changed #{repo["ssh_url"]}
part as #{repo["html_url"]}
to clone repos via https.
This script works great. If the org is large or you do this frequently you might like ghorg, a small cli to make cloning github orgs quick and easy.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
per_page is only respected up to 100; if the number is greater than this you'll have to deal with pagination