Software Development

A journal for sharing all things software development related


Clean up merged branches

Fri, 19 Jul 2019 08:53 UTC by garethbrown

Update 2020/05/21

Delete all branches except master and the current checked out branch

git branch | grep -v "master" | grep -v ^* | xargs git branch -D

Update 2020/01/19

From https://coderwall.com/p/x3jmig/remove-all-your-local-git-branches-but-keep-master

$ git branch | grep -v "master" | xargs git branch -D

This deletes all but the master branch locally. With github, cleaning up branches on github.com is pretty easy, so no need to replicate for the server from commandline.

https://github.com/garethrbrown/app-software-apps/branches


Source:

https://stackoverflow.com/questions/6127328/how-can-i-delete-all-git-branches-which-have-been-merged?page=1&tab=oldest#tab-top

Ran this 2019/07/22 - Note that it may have deleted the remote version of my current bug fix branch, but I was able to just re-push my local. Probably best done when all merged in. It won't delete branches that have 'master' or 'dev' somewhere in the name.

git branch -r --merged | grep -v master | grep -v develop | sed 's/origin///' | xargs -n 1 git push --delete origin


The information on this site is provided “AS IS” and without warranties of any kind either
express or implied. To the fullest extent permissible pursuant to applicable laws, the author disclaims all warranties, express or implied, including, but not limited to, implied warranties of merchantability, non-infringement and suitability for a particular purpose.

UI block loader
One moment please ...