Navigate back to the homepage

Clone any Private or Public repo from Organization

Have you ever wanted to clone all repos under your account or specific organization or even from the company where you work?

Ahmed Abdulrahman
Feb 3rd, 2020 • ☕️ 1 min read

Say you want to clone or backup of all github repositories under your account or specific organization or you want to contribute to an open source project. You successfully do that copy & paste repo URL and then clone them manually 😫. But there might be plenty of repos and you dont want to repeat yourself. what do you do if there plenty of repos? you will need to repeat yourself again and again 😣.

To automate this process, you can use github API together with jq processor to clone all repos with one-liner shell script.


GitHub API returns really nicely formatted JSON but there is a pretty fair amount of JSON in the response!. We’re primarily only interested to get the ssh_url, and not all the other output.

Simply we can use jq to “reformat” the JSON output from API response and include only that information. That’s done with this snippet:

1curl -s "" \
2 | jq '.[].ssh_url'

This will provide output that will look something like this:


This makes it really easy to parse out the specific information you need. Now that you’re armed with ssh_url, we need to convert the output to raw strings, not JSON texts by passing -r flag to jq then we can loop over the list and clone all repos:

1curl -s "" \
2 | jq '.[].ssh_url' -r \ # output raw strings, not JSON texts
3 | while read url; do git clone "$url"; done

Boom! You got all repos now 🔥! if you needed to clone private repos, then you will need to:

  • Add &type=private on the URL.
  • Create a personal access token as described here

snippet will look like this:

1curl -H "Authorization: token YOUR_ACCESS_TOKEN" -s \
2 "" \
3 | jq '.[].ssh_url' -r \ # output raw strings, not JSON texts
4 | while read url; do git clone "$url"; done


You create a shell function inside your .bashrc or .zshrc file:

1function cloner {
2 # you can store your access token as env variable inside `.bashrc` or `.zshrc`
3 # ex: export GITHUB_TOKEN= , and replace $1 with $GITHUB_TOKEN and $2 with $1
4 curl -H "Authorization: token $1" -s \
5 "{$2}/repos?per_page=10" \
6 | jq '.[].ssh_url' -r \ # output raw strings, not JSON texts
7 | while read url; do git clone "$url"; done

and use it like this:

1# with ENV variable
2cloner your-organization
4# without ENV variable
5cloner <your-access-token> your-organization

Did you find this useful? Buy me a coffee to give my brain a hug☕️.

Hope you liked this article. If you did, then share it. It means a lot.🙌 Thanks for reading!

Discuss on TwitterFollow @_ahmed_ab

Other things I've written

How to Automatically Sort Import Modules with ESLint

In this artcile, you’ll learn how configure ESLint to imports for us automatically.

Jan 5th, 2020 · 1 min read

How to Start Vim temporarily without settings or plugins

Sometime you want temporarily to disable your vimrc without loading any of my plugins or settings. In this article, we will see how can we do that

Jan 4th, 2020 · 1 min read

© 2018–2020
Ahmed Abdulrahman


Link to $ to $ to $