Skip to content

Instantly share code, notes, and snippets.

@ludndev
Last active May 18, 2024 14:07
Show Gist options
  • Save ludndev/4489b084de90dc7c903c7fbd9f2c7c3a to your computer and use it in GitHub Desktop.
Save ludndev/4489b084de90dc7c903c7fbd9f2c7c3a to your computer and use it in GitHub Desktop.
Extract repositories from a GitHub profile or organisation
#!/bin/bash
# required jq and gh
# jq : https://jqlang.github.io/jq/download/
# gh : https://cli.github.com/
# Check if required argument is provided
if [ -z "$1" ]; then
echo "Error: Please provide the organization name as an argument."
echo "Usage: $0 <organization_name>"
exit 1
fi
# Define organization name from argument
org_name="$1"
echo "Cloning repositories from $org_name ..."
echo ""
# Create folder for organization (if it doesn't exist)
if [ ! -d "$org_name" ]; then
mkdir "$org_name"
fi
# Change directory to organization folder
cd "$org_name"
# Loop through organization repositories
for url in $(gh repo list $org_name --limit 9999 --json url | jq -r ".[].url"); do
folderName=$(basename $url .git)
echo "> $org_name/$folderName"
if [ -d "$folderName" ]; then
cd "$folderName"
git pull
cd ..
else
git clone $url
fi
echo ""
done
@ludndev
Copy link
Author

ludndev commented May 18, 2024

example

sh get.sh username

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