Skip to content

Instantly share code, notes, and snippets.

@ams0
Created August 7, 2025 20:03
Show Gist options
  • Save ams0/3d1b9616e92b24086739a3f458c9ed43 to your computer and use it in GitHub Desktop.
Save ams0/3d1b9616e92b24086739a3f458c9ed43 to your computer and use it in GitHub Desktop.
#!/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