Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented May 26, 2016

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

@MarcBittnerRing

This comment has been minimized.

Copy link

commented Jul 22, 2018

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

@baybatu

This comment has been minimized.

Copy link

commented Dec 6, 2018

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

@gabrie30

This comment has been minimized.

Copy link

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
You can’t perform that action at this time.