#!/usr/bin/perl my @remote_branches = split ' ', `git branch -r | awk '{print $1}'`; # have to filter out the "* " my @local_branches = split ' ', `git branch | sed 's/^..//'`; my @origin_branches = grep /^origin\//, @remote_branches; my %unmerged = (map { $_ => 1 } @remote_branches), (map { $_ => 0 } @local_branches, @origin_branches); foreach my $branch (@local_branches, @origin_branches) { map { $unmerged{$_}=0 } split ' ', `git branch -r --merged "$branch" | awk '{print $1}'` } foreach my $branch (sort keys %unmerged) { print "$branch\n" if $unmerged{$branch}; }