Skip to content

Instantly share code, notes, and snippets.

@twhite96
Forked from justlaputa/unstar-all-repos.md
Created May 1, 2024 02:42
Show Gist options
  • Save twhite96/861d08dc0fa00108086e0f8c4324e3c1 to your computer and use it in GitHub Desktop.
Save twhite96/861d08dc0fa00108086e0f8c4324e3c1 to your computer and use it in GitHub Desktop.
How to unstar all your github starred repos

About

How to unstar all your github stars with API

Generate a github personal token

visit here: https://github.com/settings/tokens make sure to check repo scope, it is needed to unstar

Get all starred repos

set apikey as env variable

export APIKEY=xxxxxxxxx

first get total number of pages of your star

curl -I -H "Authorization: token $APIKEY" https://api.github.com/user/starred
HTTP/1.1 200 OK
...
Link: <https://api.github.com/user/starred?page=2>; rel="next", <https://api.github.com/user/starred?page=4>; rel="last"
...

then iterate on all pages (1 to 4)

for p in `seq 1 4`;do
echo page 
curl -s -H "Authorization: token $APIKEY" https://api.github.com/user/starred\?page\=$p | jq -r '.[] |.full_name' >>stars.txt
done

finally delete all repos in the stars.txt file

while read REPO;do
echo 
curl -X DELETE -s -H "Authorization: token $APIKEY" "https://api.github.com/user/starred/$REPO"
sleep 0.5
done<stars.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment