Created
August 7, 2025 20:03
-
-
Save ams0/3d1b9616e92b24086739a3f458c9ed43 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 -euo pipefail | |
# GitHub username | |
USERNAME="ams0" | |
# Base directories | |
BASE_DIR="$(pwd)" | |
PUBLIC_DIR="${BASE_DIR}/public" | |
PRIVATE_DIR="${BASE_DIR}/private" | |
# Create directories | |
mkdir -p "$PUBLIC_DIR" "$PRIVATE_DIR" | |
# Fetch all repos (limit 1000; increase if needed) | |
REPOS=$(gh repo list "$USERNAME" --limit 1000 --json name,sshUrl,visibility -q '.[] | [.name, .sshUrl, .visibility] | @tsv') | |
echo "π Syncing repositories for user: $USERNAME" | |
while IFS=$'\t' read -r REPO_NAME SSH_URL VISIBILITY; do | |
if [[ "$VISIBILITY" == "PUBLIC" ]]; then | |
TARGET_DIR="$PUBLIC_DIR" | |
else | |
TARGET_DIR="$PRIVATE_DIR" | |
fi | |
cd "$TARGET_DIR" | |
if [ -d "$REPO_NAME/.git" ]; then | |
echo "π₯ Pulling updates for $VISIBILITY repo: $REPO_NAME" | |
cd "$REPO_NAME" | |
git pull --ff-only | |
cd .. | |
else | |
echo "π¦ Cloning $VISIBILITY repo: $REPO_NAME" | |
git clone "$SSH_URL" | |
fi | |
done <<< "$REPOS" | |
echo "β All repositories are up to date." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment