Skip to content

Instantly share code, notes, and snippets.

@davidmerrick
Last active January 15, 2022 23:26
Show Gist options
  • Save davidmerrick/c189d31a4f3d186f187846c1f6656964 to your computer and use it in GitHub Desktop.
Save davidmerrick/c189d31a4f3d186f187846c1f6656964 to your computer and use it in GitHub Desktop.
Clone all github repos in an org
#!/bin/bash
# Note: This script requires that you have $GITHUB_TOKEN set.
# Get one here: https://github.com/settings/tokens
ORG=yourOrg
HAS_NEXT=true
i=1
while $HAS_NEXT
do
REPOS=$(curl "https://api.github.com/orgs/$ORG/repos?per_page=100&page=$i" \
-H "Accept: application/vnd.github.machine-man-preview+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" | jq .[].ssh_url)
if [[ $(echo $REPOS | wc -w) -eq 0 ]]
then
HAS_NEXT=false
fi
echo $REPOS | xargs -n 1 git clone
i=$(expr $i + 1)
done
@jitunair18
Copy link

Is there a way to make this work for private repositories?

@davidmerrick
Copy link
Author

Hey sorry @jitunair18, I'm just now seeing this. I would assume the visibility of the repo would be based on the scopes of your token. Is that not the behavior that you're seeing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment