Skip to content

Instantly share code, notes, and snippets.

@joemiller
Last active December 28, 2020 18:02
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joemiller/2dd72670e37769cb647c to your computer and use it in GitHub Desktop.
Save joemiller/2dd72670e37769cb647c to your computer and use it in GitHub Desktop.
clone all repos from an org, including private repos
#!/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."
@asmjahid
Copy link

it not clone all the repo from org....it just clone 100 repo.

@MarcBittnerRing
Copy link

per_page is only respected up to 100; if the number is greater than this you'll have to deal with pagination

@baybatu
Copy link

baybatu commented Dec 6, 2018

Thanks for the script. I changed #{repo["ssh_url"]} part as #{repo["html_url"]} to clone repos via https.

@gabrie30
Copy link

gabrie30 commented May 6, 2019

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