git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joey Hess <joey@kitenet.net>
To: git@vger.kernel.org
Subject: finding unmerged branches
Date: Thu, 27 Aug 2009 18:02:41 -0400	[thread overview]
Message-ID: <20090827220241.GA1413@gnu.kitenet.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 1143 bytes --]

My situation is this: My project has a lot of remotes with
lots of branches; about 250 branches in total. I want to
figure out which of these branches to look at to consider
merging.

So, I reach for git branch -a --no-merged master; that's what
its man page says its for. But this still finds 120 branches,
and a lot of them are not things I want to look at. Many of
them are copies of some of my own branches.

What I really want is a way to find remote branches that
are not merged with any of my local branches (or any origin
branches). A slow and stupid implementation of that is in the
attached git-unmerged script, and it weeds the branch list
down to 68 branches, which are mostly really ones I might
want to look at.

So, three questions:

* Is this situation somewhat common, or an I doing something wrong?
  (Assuming that I have a good reason to want to look at remote 
  branches rather than waiting to get merge requests.)
* Is there a better way to accomplish this than a slow perl script that
  runs git branch -r --merged foreach of my branches?
* Should git have something builtin to handle this case better?

-- 
see shy jo

[-- Attachment #2: git-unmerged --]
[-- Type: text/plain, Size: 582 bytes --]

#!/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};
}

             reply	other threads:[~2009-08-27 22:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-27 22:02 Joey Hess [this message]
2009-08-27 22:22 ` finding unmerged branches Avery Pennarun
2009-08-28  0:54   ` Joey Hess
2009-08-27 22:35 ` Björn Steinbrink
2009-08-27 23:25   ` Junio C Hamano
2009-08-28  0:44   ` Joey Hess
2009-08-28  2:08 ` Joey Hess

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090827220241.GA1413@gnu.kitenet.net \
    --to=joey@kitenet.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).