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"]} ]}'
@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