How to clone all github repositories for specific organization?

Situation

You need to clone all repos for your organization on github/on-premise github. Since there might be plenty of repos you don’t want to repeat yourself and prefer automate this process.

Solution

  • Create an API token by going to Account Settings → Applications

  • Clone repos:

$ GITHUB_BASE_URL={api.github.com|yourcompanygithub}; CONTEXT={users|orgs}; NAME={username|orgname}; ACCESS_TOKEN={yourtoken}
$ curl "https://$GITHUB_BASE_URL/api/v3/$CONTEXT/$NAME/repos?page=1&per_page=100&access_token=$ACCESS_TOKEN" \
     | jq '.[] | .clone_url' \
     | xargs -L1 git clone

Notes:

  1. CONTEXT=users and NAME=yourusername will clone all your repositories.

  2. CONTEXT=orgs and NAME=yourorgname will clone all repositories of your organization.

  3. The solutions assumes you have jq installed. If you haven’t, it’s time to do it.

Oleksii Zghurskyi