Upon an organization name clone all available repositories to your computer


In there are a lots of organization that offers code templates, exercies, and material for courses and tranining online and it comes handry the posibility of clone the entire set of repositories available (private repositories may be exluded per the owner of the organization account but it works for all public repositories).

What you need to setup before get started in github CLI API also known as GH. You can download from the official page Once your GH client is installed in your system you need to proceed to authenticate yourself to via creating a user personal token so the client can impersonate you and access the repositories for you. Such process of getting a token to impersonate github api calls is described here

Now it is time to collect some repositories from an organization. I will use as example this organization And my goal is to clone all public repositories into my local

First step is capture the clone url for each of the repositories within the organization

gh api --paginate \
  -H "Accept: application/vnd.github+json" \
  /orgs/quick-tutorials-with-aws-cloud/repos | jq -r '.[].ssh_url' | nl

The above example will output the git clone ssh urls to your screen. Lets modify the script to save the list into a text file file

gh api --paginate \"Accept: application/vnd.github+json" \
  -H "Accept: application/vnd.github+json" \
  /orgs/quick-tutorials-with-aws-cloud/repos | jq -r '.[].ssh_url' | nl >

Since the list is enumerated by the nl command and we are only interested in the ssh git clone URL lets strip off the enumeration and start cloning the repositories.

This is the final step of this practice

for repository in `cat | awk '{print $2}'`; do git clone $repository; done;

Now you are able to clone the available repositories from any organization whose repos are public to the outside world.


Jaziel Lopez


1.0.0 Initial (and prob.the final) Q3 2022