Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save maskas/e8218182ac583b547692 to your computer and use it in GitHub Desktop.
Save maskas/e8218182ac583b547692 to your computer and use it in GitHub Desktop.
Remove all remote branches that are merged to master, except 20 last ones. Sort by most recent commit date.
#Remove remote branches, that are merged to master. Leave 20 latest branches just in case.
git pull
for branch in `git branch -r --merged origin/master | grep -v HEAD`;do echo -e `git show --format="%at" $branch | head -n 1` \\t$branch; done | sort -r | cut -c 20- | awk 'NR>20' | while read line ; do git push origin --delete $line; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment