Skip to content

Instantly share code, notes, and snippets.

@astrolemonade
Forked from justlaputa/unstar-all-repos.md
Last active June 28, 2022 17:04
Show Gist options
  • Select an option

  • Save astrolemonade/34bdff3f0f555e1e4150684aa4e03777 to your computer and use it in GitHub Desktop.

Select an option

Save astrolemonade/34bdff3f0f555e1e4150684aa4e03777 to your computer and use it in GitHub Desktop.
delete all github stars

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 .5
done<stars.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment