{"thread":{"id":"35892","subject":"How to delete all merged branches?","startedAt":"2014-02-16T17:37:12Z","lastAt":"2014-02-16T19:17:22Z","messageCount":2,"participants":["Stefan Beller","Jamie Couture"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"234904","messageId":"5300F748.2060805@googlemail.com","threadId":"35892","inReplyTo":null,"subject":"How to delete all merged branches?","fromName":"Stefan Beller","fromEmail":"stefanbeller@googlemail.com","sentAt":"2014-02-16T17:37:12Z","receivedAt":"2014-02-16T17:37:12Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Hi,\n\nso I tend to accumulate lots of branches as I'd do one \nbranch per feature. When cleaning up, I'd like to \ndelete all branches, which have been merged.\nI could use \n\t$ git branch -d (which was merged already?) ^C\n\t$ git branch --merged # let's find out\n\t...\n\t$ # Now run git branch -d with each of the branches.\n\nThis kind of question has already been discussed, \nhttp://stackoverflow.com/questions/6127328/how-can-i-delete-all-git-branches-which-are-already-merged\nsuggests:\n\tgit branch --merged | grep -v \"\\*\" | xargs -n 1 git branch -d\n\nNow it seems as if this operation would be needed by quite a few people\nactually. Maybe it's time to integrate into git? I'd be interested, which\nway would be the most git-like way to do it.\nI could think of:\n\t$ git branch -d --merged # no need to specifiy a branch iff --merged is given with -d\n\t$ git branch --delete-merged \t# comes as an new extra option, doesn't clutter other commands\n\t$ git branch -d keyword-for-all-merged-branches\n\nBefore starting such a feature, I'd like to hear input of others.\n\nThanks,\nStefan\n"},{"id":"234906","messageId":"20140216191721.GA29471@neptune","threadId":"35892","inReplyTo":"5300F748.2060805@googlemail.com","subject":"Re: How to delete all merged branches?","fromName":"Jamie Couture","fromEmail":"jamie.couture@gmail.com","sentAt":"2014-02-16T19:17:22Z","receivedAt":"2014-02-16T19:17:22Z","isPatch":false,"sender":{"key":"jamie.couture@gmail.com","avatar":null},"body":"On Sun, Feb 16, 2014 at 06:37:12PM +0100, Stefan Beller wrote:\n> Hi,\n> \n> so I tend to accumulate lots of branches as I'd do one \n> branch per feature. When cleaning up, I'd like to \n> delete all branches, which have been merged.\n> I could use \n> \t$ git branch -d (which was merged already?) ^C\n> \t$ git branch --merged # let's find out\n> \t...\n> \t$ # Now run git branch -d with each of the branches.\n> \n> This kind of question has already been discussed, \n> http://stackoverflow.com/questions/6127328/how-can-i-delete-all-git-branches-which-are-already-merged\n> suggests:\n> \tgit branch --merged | grep -v \"\\*\" | xargs -n 1 git branch -d\n\nprobably saner to check where you are first, and have it conform to\nsome branch naming scheme; maybe someting like:\n\n - check you're on master\n - only consider branches that begin with first-last-/\n\n-- 8< --\nhead=$(git rev-parse --verify HEAD)\nmaster=$(git rev-parse --verify master)\n\nif test \"$head\" != \"$master\"; then\n    echo \"You must be on master\"\n    exit 1\nfi\n\ngit branch --merged  |\nsed -n -e 's/\\ *//' -e '/^[^/][^/]\\//p' |\nxargs git branch -d\n-- 8< --\n\n> \n> Now it seems as if this operation would be needed by quite a few people\n> actually. Maybe it's time to integrate into git? I'd be interested, which\n> way would be the most git-like way to do it.\n> I could think of:\n> \t$ git branch -d --merged # no need to specifiy a branch iff --merged is given with -d\n> \t$ git branch --delete-merged \t# comes as an new extra option, doesn't clutter other commands\n> \t$ git branch -d keyword-for-all-merged-branches\n> \n> Before starting such a feature, I'd like to hear input of others.\n"}]}