Storage organization
To clone all repositories from your organization, try the following single-line shell:
GHORG=company; curl "https://api.github.com/orgs/$GHORG/repos?per_page=1000" | grep -o 'git@[^"]*' | xargs -L1 git clone
User repositories
Cloning everyone using the Git repository URL:
GHUSER=CHANGEME; curl "https://api.github.com/users/$GHUSER/repos?per_page=1000" | grep -o 'git@[^"]*' | xargs -L1 git clone
Clone everyone using the Clone URL:
GHUSER=CHANGEME; curl "https://api.github.com/users/$GHUSER/repos?per_page=1000" | grep -w clone_url | grep -o '[^"]\+://.\+.git' | xargs -L1 git clone
Here is a useful shell function that you can add to custom launch files (using curl + jq ):
# Usage: gh-clone-user (user) gh-clone-user() { curl -sL "https://api.github.com/users/$1/repos?per_page=1000" | jq -r '.[]|.clone_url' | xargs -L1 git clone }
Private repositories
If you need to clone private repositories, you can add an authorization token in your header, for example:
-H 'Authorization: token <token>'
or pass it in the parameter ( ?access_token=TOKEN ), for example:
curl -s "https://api.github.com/users/$GHUSER/repos?access_token=$GITHUB_API_TOKEN&per_page=1000" | grep -w clone_url | grep -o '[^"]\+://.\+.git' | xargs -L1 git clone
Notes:
- To get only personal repositories, add
type=private to the query string. - Another way is to use
hub after setting up the API key.
See also:
Tips :
- To increase the speed, set the number of parallel processes by specifying the -P parameter for -P4 ( -P4 = 4 processes).
- If you need to increase the limits of GitHub, try to authenticate by specifying your API key.
- Add --recursive to enter registered submodules and update all nested submodules inside.
kenorb Sep 26 '15 at 23:23 2015-09-26 23:23
source share