Last active
May 18, 2024 14:07
-
-
Save ludndev/4489b084de90dc7c903c7fbd9f2c7c3a to your computer and use it in GitHub Desktop.
Extract repositories from a GitHub profile or organisation
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 | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example
sh get.sh username