Skip to content

Instantly share code, notes, and snippets.

@Ithildir
Created March 19, 2019 16:25
Show Gist options
  • Save Ithildir/dfd3071af375e7872444063afecc20df to your computer and use it in GitHub Desktop.
Save Ithildir/dfd3071af375e7872444063afecc20df to your computer and use it in GitHub Desktop.
Clone all repositories in a GitHub organization
#!/bin/bash
ORG=XXX
GITHUB_USER=XXX
GITHUB_TOKEN=XXX
SEARCH_TERM='ssh_url'
SSH_REGEX='s#.*\(git*@[^"]*\).*#\1#;p'
function get_repos {
curl -s "https://api.github.com/orgs/${ORG}/repos?page=$1&per_page=100" -u ${GITHUB_USER}:${GITHUB_TOKEN} | grep ${SEARCH_TERM} | sed -e "${SSH_REGEX}"
}
echo "Starting to clone github org: ${ORG}'s repos"
for x in $(seq 1 100); do
repos=$(get_repos "${x}")
while read -r repo; do
if ! [[ "$repo" =~ /old- ]]; then
git clone "${repo}"
fi
done <<< "${repos}"
done
echo "Finished cloning ${ORG} repos"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment