'How to unwatch multiple repos easily on github?
I realize I watch too many repos in GitHub and the only way I've found to unwatch many of them is going to github.com/my_user_name/following, getting inside each of them and pressing Unwatch button.
Isn't there any way to unwatch them faster and easily?
Solution 1:[1]
Native JS version of a previous answer. Navigate to https://github.com/watching and then run:
Oneliner:
Array.prototype.slice.apply(document.querySelectorAll('.js-subscription-row')).forEach(el => { const org = el.querySelector('a[href^="/YOUR_ORG"]'); if (org) el.querySelector('button').click()})
Unwrapped:
const org = 'YOUR_ORG'
const query = document.querySelectorAll('.js-subscription-row')
const rows = Array.prototype.slice.apply(query)
rows.forEach(function (el) {
const org = el.querySelector('a[href^="/' + org + '"]')
if (org) el.querySelector('button').click()
})
Solution 2:[2]
Organisation specific
If you just want to unwatch repos from a single organisation, you can use this from https://github.com/watching
$('.js-subscription-row').each(function(){
var isYourOrganisation = $(this).find("a[href^='/YOUR_ORG']");
if(isYourOrganisation.length){
$(this).find('button:contains("Unwatch")').click();
}
});
Substitute YOUR_ORG with whatever your organisation is called.
Solution 3:[3]
Github has an API. You could write a script to do this using Github's API, particularly the part that deals with watching repos.
Solution 4:[4]
I haven't seen any but, As we have power of the entire universe(in short we are developers). Use their developer API and create a small tool. The API is very descriptive,
Solution 5:[5]
A few comments have mentioned the Unwatch all button at https://github.com/watching
Here's a picture:
Solution 6:[6]
I've also found a command-line tool that use the GitHub API to unwatch multiple repositories: https://www.npmjs.com/package/github-unwatch-org-repos
I'm not a fan of command-line tools that want my password in plain text on the command line (thus visible to all system users who run 'ps' at the right time, and also stored in plain text in ~/.bash_history unless you take extreme care to avoid that), so I haven't tried it.
Solution 7:[7]
Unwatch all button on https://github.com/watching is available.
An alternative method is to use this script.
#! /bin/bash
# dry run:
# ./github-unwatch.bash [unwatch repository pattern] [github account] [github token]
#
# execute actually:
# ./github-unwatch.bash [unwatch repository pattern] [github account] [github token] run
set -eu
readonly REPOSITORY_PATTERN="$1"
readonly CREDENTIALS="$2:$3"
readonly RUN="${4:-dry-run}"
page=1
targets=()
while :
do
result=($( curl \
-u $CREDENTIALS \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/user/subscriptions?per_page=100&page=$page" \
| jq -r '.[].full_name' ))
if [[ ${#result[@]} -eq 0 ]]; then
break
fi
for e in "${result[@]}"
do
if [[ $e =~ $REPOSITORY_PATTERN ]]; then
targets+=($e)
fi
done
page=$((++page))
done
if [[ ${#targets[@]} -eq 0 ]]; then
exit 0
fi
for target in "${targets[@]}"
do
echo "Unwatch: $target"
if [[ "$RUN" == "run" ]]; then
curl \
-u $CREDENTIALS \
-X DELETE \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/$target/subscription"
fi
done
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Community |
| Solution 2 | Ralph Cowling |
| Solution 3 | Daniel Serodio |
| Solution 4 | TeaCupApp |
| Solution 5 | cellepo |
| Solution 6 | Marius Gedminas |
| Solution 7 |

