Skip to content

Instantly share code, notes, and snippets.

@nucliweb
Last active September 23, 2021 10:12
Show Gist options
  • Save nucliweb/920aa39c250bde7facf7 to your computer and use it in GitHub Desktop.
Save nucliweb/920aa39c250bde7facf7 to your computer and use it in GitHub Desktop.
Clone all repos from a GitHub organization

Publics repos

With Ruby 1.8 (default version on MacOS) :

sudo gem install json
curl -s https://api.github.com/orgs/[ORGANIZATION]/repos | ruby -rubygems -e 'require “json”; JSON.load(STDIN.read).each {|repo| %x[git clone #{repo["ssh_url"]} ]}'

With Ruby 1.9+, the json library is by default thus you just use :

curl -s https://api.github.com/orgs/[ORGANIZATION]/repos | ruby -rjson -e 'JSON.load(STDIN.read).each {|repo| %x[git clone #{repo["ssh_url"]} ]}'

Private repos

curl -u [[USERNAME]] -s https://api.github.com/orgs/[[ORGANIZATION]]/repos?per_page=200 | ruby -rubygems -e 'require "json"; JSON.load(STDIN.read).each { |repo| %x[git clone #{repo["ssh_url"]} ]}'
@ktiniatros
Copy link

ktiniatros commented Jun 5, 2019

For enterprise github:

curl -H "Authorization: token [YourPersonalToken]" -s https://[YourCompanyHostname]/api/v3/orgs/[YourOrganisation]/repos?per_page=200 | ruby -rubygems -e 'require "json"; JSON.load(STDIN.read).each { |repo| %x[git clone #{repo["ssh_url"]} ]}'

You can generate your personal token at Settings/Developer Settings or directly to this url: https://[YourCompanyHostname]/settings/tokens (make sure you select the right scope repo/public_repo)

@nucliweb
Copy link
Author

nucliweb commented Jun 5, 2019

Thanks @ktiniatros

@paravz
Copy link

paravz commented Jun 28, 2019

if you have go, it becomes easier:

curl -sS -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/user/repos?per_page=200 \
	| jq -r '.[].svn_url' \
	| while read svn_url; \
	do go get -d "${svn_url##*://}"; done

@nucliweb
Copy link
Author

nucliweb commented Jul 8, 2019

Thank you @paravz, in your solution I love it.
Reminder we need have installed jq

@gabrie30
Copy link

gabrie30 commented Aug 8, 2019

ghorg is a cli that does this. It supports github, gitlab, and bitbucket.

@Justintime50
Copy link

After some searching and frustrations of my own not being able to do this easily, I built out a project that allows for public and private repo cloning of both personal and organization repos. Perfect for grabbing everything you'd need:

https://github.com/Justintime50/github-archive

@aterreno
Copy link

ghorg is a cli that does this. It supports github, gitlab, and bitbucket.

Looks awesome works like a charm thanks!

@sanzgadea
Copy link

sanzgadea commented Jul 29, 2020

At Ruby 2.5 ubygems.rb was removed from Ruby, if you are using a higher version you should replace ruby -rubygems by ruby -rrubygems

The whole command for private repos would then be:
curl -u [[USERNAME]] -s https://api.github.com/orgs/[[ORGANIZATION]]/repos?per_page=200 | ruby -rrubygems -e 'require "json"; JSON.load(STDIN.read).each { |repo| %x[git clone #{repo["ssh_url"]} ]}'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment