DEV Community

Adhishatanaka
Adhishatanaka

Posted on Edited on

How to Find users who don't follow you back in Github

Here is a quick GitHub CLI trick to easily find users who don't follow you back (unfollowers). It fetches your following and followers lists via the GitHub API, compares them, and outputs the names of those who haven't followed.

First Authenticate in github cli using

gh auth refresh -h github.com -s user
Enter fullscreen mode Exit fullscreen mode

Then ,

💻 macOS / Linux:

ME=$(gh api user -q .login); comm -13 <(gh api --paginate "users/$ME/followers" -q '.[].login' | sort) <(gh api --paginate "users/$ME/following" -q '.[].login' | sort) | while read u; do gh api -X DELETE "user/following/$u" && echo "unfollowed $u"; done

Enter fullscreen mode Exit fullscreen mode

🪟 Windows (PowerShell):

$me = gh api user -q .login
$followers = gh api --paginate "users/$me/followers" -q '.[].login'
$following = gh api --paginate "users/$me/following" -q '.[].login'
$following | Where-Object { $_ -notin $followers } | ForEach-Object {
    gh api -X DELETE "user/following/$_"
    Write-Host "unfollowed $_"
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)