Skip to content

Instantly share code, notes, and snippets.

@horothesun
Created January 11, 2022 16:26
Show Gist options
  • Save horothesun/aefac04967f3fd7a406899b9b7a45432 to your computer and use it in GitHub Desktop.
Save horothesun/aefac04967f3fd7a406899b9b7a45432 to your computer and use it in GitHub Desktop.
Clone all team repos
#!/bin/bash
# Usage: GITHUB_OWNER=<owner> GITHUB_TEAM=<team> clone_all_team_repos.sh
#
# Dependencies: gh, jq
[ -z "$GITHUB_OWNER" ] && echo "Error: GITHUB_OWNER must be defined" && exit 10
[ -z "$GITHUB_TEAM" ] && echo "Error: GITHUB_TEAM must be defined" && exit 20
function cloneIfDoesNotExist() {
if [ ! -d "$1" ]; then
FULL_REPO=$GITHUB_OWNER/$1
echo "⬇️ Cloning $FULL_REPO ..."
gh repo clone $FULL_REPO
else
echo "👍 $1 already exists!"
fi
}
TEAM_REPOS=$(gh api /orgs/$GITHUB_OWNER/teams/$GITHUB_TEAM/repos\?per_page=100 --paginate | jq -r '.[].name')
for REPO in $TEAM_REPOS; do cloneIfDoesNotExist $REPO; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment