-
-
Save gadelkareem/cc1d3e27de239f691cbe720b5b28797b to your computer and use it in GitHub Desktop.
Clone all private repos of an organization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
#optional change working directory | |
DIR=${1-$(pwd)} | |
cd $DIR | |
USER="Github username" | |
TOKEN=$GITHUB_TOKEN | |
ORGANIZATION="organization name" | |
REPOS=$(curl -s https://api.github.com/orgs/$ORGANIZATION/repos?type=private\&per_page=1000 -u ${USER}:${TOKEN} | jq .[].ssh_url | sed -e 's/^"//' -e 's/"$//') | |
for repo in $REPOS | |
do | |
echo "Repo found: $repo" | |
ret=0 | |
git clone $repo 2> /dev/null || ret=1 | |
if [ $ret -ne 0 ]; then | |
repo_dir=`echo $repo | sed 's/.*\///' | sed 's/\.git//' ` | |
if [ ! -d $repo_dir ]; then | |
echo "Error: Failed to clone $repo" | |
fi | |
fi | |
done | |
for repo in */ ; do | |
echo "Pulling changes for $repo" | |
cd $repo | |
git pull & | |
cd .. | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment