Jens A. Koch

bash script for cloning all repositories of an github organization (clone-org.sh)

You need to adjust the GITHUB_ORGANIZATION to your needs.

touch clone-org.sh
chmod +x clone-org.sh

 

You need to load your SSH KEY,
else you will run into the following error:
Permission denied (publickey).
fatal: The remote end hung up unexpectedly.

Take care!

Filecontent:

#!/bin/bash

# The script clones all repositories of an GitHub organization.
#
# Author: Jens A. Koch
# Date: 24.09.2012
#

# the github organization to fetch all repositories for
GITHUB_ORGANIZATION="WPN-XM"

# the git clone cmd used for cloning each repository
# the parameter recursive is used to clone submodules, too.
GIT_CLONE_CMD="git clone --quiet --mirror --recursive "

# fetch repository list via github api
# grep fetches the json object key ssh_url, which contains the ssh url for the repository
REPOLIST=curl --silent https://api.github.com/orgs/${GITHUB_ORGANIZATION}/repos -q | grep "\"ssh_url\"" | awk -F': "' '{print $2}' | sed -e 's/",//g'

# loop over all repository urls and execute clone
for REPO in $REPOLIST; do
${GIT_CLONE_CMD}${REPO}
done

 

2 Comments »

2 Responses

  1. Christian Weiske Says:

    This doesn’t work if the organization has so many repositories that they are split onto several pages.

    Github adds a Link header then, e.g. in https://api.github.com/orgs/pear/repos

  2. jakoch Says:

    When i find the time, i will take a look at this issue.