How do I get the list of branches not merged into master, ordered by most recent commit?

You could combine the two, like this:

git for-each-ref --sort=-committerdate --format="%(committerdate:short) %(refname:short)" --count=15 $(git branch -r --no-merged origin/master | sed -e 's#^ *#refs/remotes/#')

That will limit the for-each-ref to processing only the branches that branch --no-merged reports...

Edit: fixed formatting of git branch output after actually testing...


Can't you just grep out branch2?

Basically, something like:

for branch in `git branch -r --no-merged origin/master`; do git for-each-ref --sort=-committerdate --format='%(committerdate:short) %(refname:short)' --count=15 refs/remotes/origin/ | grep $branch; done;

That worked for me given your sample output.

Tags:

Git