Skip to content

Instantly share code, notes, and snippets.

@igmarin
Created May 31, 2026 04:30
Show Gist options
  • Select an option

  • Save igmarin/e86d134a7a0fc7cd72730454e0500358 to your computer and use it in GitHub Desktop.

Select an option

Save igmarin/e86d134a7a0fc7cd72730454e0500358 to your computer and use it in GitHub Desktop.
bash auto_achive.sh (auto achive all project that do not have activity in the last 6 months
#!/bin/bash
# 1. Your GitHub username
USERNAME="yourusername"
# Set this to 'true' to test the script without actually archiving anything
DRY_RUN=true
# 2. Calculate the cutoff date (6 months ago)
if [[ "$OSTYPE" == "darwin"* ]]; then
CUTOFF_DATE=$(date -v-6m +%Y-%m-%dT%H:%M:%SZ)
else
CUTOFF_DATE=$(date -d "6 months ago" +%Y-%m-%dT%H:%M:%SZ)
fi
echo "πŸ“… Looking for repositories with no activity since: $CUTOFF_DATE"
if [ "$DRY_RUN" = true ]; then
echo "πŸ‘€ DRY RUN ACTIVE: No real changes will be made."
fi
echo "--------------------------------------------------------"
# 3. Fetch, filter, and archive repos (excluding forks, including private ones)
gh repo list $USERNAME --limit 1000 --source --no-archived --json name,pushedAt --jq ".[] | select(.pushedAt < \"$CUTOFF_DATE\") | .name" | while read -r repo; do
if [ "$DRY_RUN" = true ]; then
echo "πŸ” [Simulation] Would archive: $USERNAME/$repo (Last push: over 6 months ago)"
else
echo "πŸ“¦ Archiving $USERNAME/$repo..."
gh repo archive "$USERNAME/$repo" --yes
fi
done
echo "--------------------------------------------------------"
echo "βœ… Process complete!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment