Skip to content

Instantly share code, notes, and snippets.

@justlaputa
Last active May 1, 2024 02:42
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save justlaputa/a6da84981eca963817e652b5f2452cfc to your computer and use it in GitHub Desktop.
Save justlaputa/a6da84981eca963817e652b5f2452cfc 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
@qiukun
Copy link

qiukun commented Jan 22, 2021

should curl -X DELETE -s -H "Authorization: token $APIKEY" https://api.github.com/user/starred/ be curl -X DELETE -s -H "Authorization: token $APIKEY" https://api.github.com/user/starred/$REPO? (missing $REPO here)

@Carol1992
Copy link

should curl -X DELETE -s -H "Authorization: token $APIKEY" https://api.github.com/user/starred/ be curl -X DELETE -s -H "Authorization: token $APIKEY" https://api.github.com/user/starred/$REPO? (missing $REPO here)

you are right, thank you.

@Xyde
Copy link

Xyde commented Sep 13, 2021

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

I couldn't run part of this code (I use Windows OS). The reasoning is that right after creating stars.txt, there is a carriage return at the end of each line there was a \r which messed up the deletion process.

I fixed my issue by Find and Replace All \r into \n in Notepad3 (Sublime Text did not detect any \r). The code is perfect, thank you very much.

@f9n
Copy link

f9n commented Oct 19, 2022

Thanks. 🚀

#!/usr/bin/env bash

set -o errexit
set -o pipefail
set -o nounset

STARS_PAGE_COUNT=20
STARS_FILE=stars.txt
DELETE_SLEEP_TIME=.5

function get_all_star_repos() {
  for p in $(seq 1 $STARS_PAGE_COUNT);do
    echo "page: $p"
    curl -s -H "Authorization: token $APIKEY" https://api.github.com/user/starred\?page\=$p | jq -r '.[] |.full_name' >> $STARS_FILE
  done
}

function remove_all_star_repos() {
  while read REPO;do
    echo "REPO: $REPO"
    curl -X DELETE -s -H "Authorization: token $APIKEY" https://api.github.com/user/starred/$REPO
    sleep $DELETE_SLEEP_TIME
  done < $STARS_FILE
}

get_all_star_repos
remove_all_star_repos

@ZirconXi
Copy link

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

I couldn't run part of this code (I use Windows OS). The reasoning is that right after creating stars.txt, there is a carriage return at the end of each line there was a \r which messed up the deletion process.

I fixed my issue by Find and Replace All \r into \n in Notepad3 (Sublime Text did not detect any \r). The code is perfect, thank you very much.

The above solution is no longer suitable for the latest Github API (2022-11-28). This is my solution.

while read REPO;do
curl -L -X DELETE -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $APIKEY" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/user/starred/$REPO
done < stars.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment