Skip to content

Instantly share code, notes, and snippets.

@caniszczyk
Created October 9, 2012 04:25
Show Gist options
  • Save caniszczyk/3856584 to your computer and use it in GitHub Desktop.
Save caniszczyk/3856584 to your computer and use it in GitHub Desktop.
Clone all repos from a GitHub organization
curl -s https://api.github.com/orgs/twitter/repos?per_page=200 | ruby -rubygems -e 'require "json"; JSON.load(STDIN.read).each { |repo| %x[git clone #{repo["ssh_url"]} ]}'
@Vaisakhkm2625
Copy link

  • | xargs -n1 git clone

we can essentially remove jq and directly use gh

gh repo list --json=sshUrl --limit 1000 -q ".[].sshUrl" | xargs -n1 git clone

though, it's asking for ssh passcode... any idea how to overcome that?

@Vaisakhkm2625,

If you don't want to use SSH protocol, just run this command1:

gh auth login

It's interactive, so there are a couple of selections you need to make first i.e., selecting the host (GitHub or GitHub Enterprise) etc. but eventually you will reach:

What is your preferred protocol?
> http
  ssh

Select ssh, and it gh will save your preference for future gh commands. I'd recommend doing it this way so that gh can manage your credentials, BUT you can probably skip all the above by running2:

gh config set git_protocol ssh

Oops, typo! Instead of the one-liner immediately above, to use http instead of ssh the command should read

"gh config set git_protocol ssh **http**" (see diff below).

- gh config set git_protocol ssh
# use the below for http protocol (to bypass ssh requirement)
+ gh config set git_protocol http

Doy! 😄

Footnotes

1. [`gh auth login` (cli.github.com/manual)](https://cli.github.com/manual/gh_auth_login) [↩](#user-content-fnref-1-9e7baee31a028e56fce81af59af26625)

2. [`gh config set` (cli.github.com/manual)](https://cli.github.com/manual/gh_config_set#:~:text=%24%20gh%20config%20set%20git_protocol%20ssh%20%2D%2Dhost%20github.com) [↩](#user-content-fnref-2-9e7baee31a028e56fce81af59af26625)

got around by using ssh agent

eval "$(ssh-agent -s)"  # Start the ssh-agent
ssh-add ~/.ssh/id_rsa    # Add your SSH key:
gh repo list --json=sshUrl --limit 1000 -q ".[].sshUrl" | xargs -n1 git clone

@pz-max
Copy link

pz-max commented Feb 9, 2025

Here is my Linux guide using the GitHub CLI gh and ssh:
🖊️ Install GitHub CLI: https://github.com/cli/cli/blob/trunk/docs/install_linux.md#installing-gh-on-linux-and-bsd
🖊️ Clone all GitHub packages under org name: gh repo list <ADD ORG NAME> --json=sshUrl --limit 1000 -q ".[].sshUrl" | xargs -n1 git clone

Example that worked for me (for this organization repo: https://github.com/orgs/NREL-Sienna) :
gh repo list NREL-Sienna --json=sshUrl --limit 1000 -q ".[].sshUrl" | xargs -n1 git clone

@wefalltomorrow
Copy link

gh repo list theUSERorORG --json=nameWithOwner --limit 1000 -q ".[].nameWithOwner"  | %{gh repo clone $_}

This worked wonderfully, thank you!

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