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:
CONTEXT=users and NAME=yourusername will clone all your repositories.
CONTEXT=orgs and NAME=yourorgname will clone all repositories of your organization.
The solutions assumes you have jq installed. If you haven’t, it’s time to do it.