Skip to content

Instantly share code, notes, and snippets.

@fabioperrella
Last active November 26, 2023 23:24
Show Gist options
  • Save fabioperrella/1f56229a4c532fc000ed to your computer and use it in GitHub Desktop.
Save fabioperrella/1f56229a4c532fc000ed to your computer and use it in GitHub Desktop.
Bash script to clean git merged branches (local and remote). Thanks to Eron Junior to introduce me the command "git fetch -p"
#!/bin/sh
set -xe
git checkout master
git fetch
git pull
git branch -r --merged | grep origin | grep -v '>' | grep -v master | xargs -L1 | cut -d"/" -f2- | xargs git push origin --delete || true
git branch --merged | grep -v master | xargs git branch -d || true
git fetch -p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment