Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Git Repository House Keeping

Remove all merged (into master) remote branches First run with --dry-run and check if everything is OK

git branch -r --merged origin/master | 
grep origin | 
grep -v '>' | 
grep -v master | 
xargs -L1 | 
cut -d"/" -f2- | 
xargs git push origin --dry-run --delete

Remove tracking branches if the remote branch is deleted

git remote prune origin

Remove all local branches if remote upstreams are removed

git branch -vv | grep 'origin/.*: gone]' | awk '{print $1}' | xargs git branch -d 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment