Skip to content

Instantly share code, notes, and snippets.

@codebryo
Last active November 28, 2022 10:38
Show Gist options
  • Save codebryo/29ba9b201a8b74aa02ef332e48bbb65a to your computer and use it in GitHub Desktop.
Save codebryo/29ba9b201a8b74aa02ef332e48bbb65a to your computer and use it in GitHub Desktop.
If you want to quickly delete all branches visible on one page in GitHub (e.g. stale branches) this script will click all those bucket buttons for you.
// Self executing loop staggered with delete requests to deal with local GH js rerenders
// Experiment with the timedelay of 1000 by default
var buttons = Array.from(document.querySelectorAll('button[title^="Delete "]'));
function loopIt(x) {
setTimeout(() => {
buttons[x].click();
if(x < buttons.length -1) loopIt(x+1);
}, 1000);
};
loopIt(0);
@codebryo
Copy link
Author

Just execute that script line in the browser console on the page you are looking at ... and with the automatic reload all you need to do is click up and Enter again till you are through with all the branches!

@codebryo
Copy link
Author

Updated the script to deal with the UI lock by GitHub

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