Skip to content

Instantly share code, notes, and snippets.

@ashleyconnor
Last active January 28, 2025 03:24
Show Gist options
  • Save ashleyconnor/a6a67fe1d02ecd9094ffa586256ad05b to your computer and use it in GitHub Desktop.
Save ashleyconnor/a6a67fe1d02ecd9094ffa586256ad05b to your computer and use it in GitHub Desktop.
Remove all GitHub stars
#!/usr/bin/env bash
set -o errexit
set -euo pipefail
[[ "${DEBUG:-}" == 'true' ]] && set -o xtrace
IFS=$'\n\t'
token=$(gh auth token)
# TODO: Check X-OAuth-Scopes repo
# get number of pages
pages=$(curl -I -H "Accept: application/vnd.github.v3+json" -H "Authorization: token ${token}" \
-s -o /dev/null -w '%header{link}' https://api.github.com/user/starred | grep -oP '(?<=page=)\d+(?=>; rel="last")' || echo "1")
# remove any previous stars.txt
rm -f stars.txt
# get all starred repos
for p in {1..$pages}; do
curl -H "Accept: application/vnd.github.v3+json" -H "Authorization: token ${token}" \
-s https://api.github.com/user/starred\?page\=$p |
jq -r '.[] |.full_name' >> stars.txt;
done
# unstar all starred repos
echo "Removing $(wc -l stars.txt | awk '{print $1}') repos"
while read REPO; do
printf "."
curl -H "Accept: application/vnd.github.v3+json" -H "Authorization: token ${token}" \
-H "X-GitHub-Api-Version:2022-11-28" -s -o /dev/null -X "DELETE" https://api.github.com/user/starred/"${REPO}"
done<stars.txt
echo -e "\nComplete"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment