Skip to content

Instantly share code, notes, and snippets.

@gadelkareem
Forked from potter0815/cloneall.sh
Last active November 28, 2019 13:10
Show Gist options
  • Save gadelkareem/cc1d3e27de239f691cbe720b5b28797b to your computer and use it in GitHub Desktop.
Save gadelkareem/cc1d3e27de239f691cbe720b5b28797b to your computer and use it in GitHub Desktop.
Clone all private repos of an organization
#!/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