Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

For our buildbot, I want to display the most recently-updated active (non-released) branches. Let's say I have a master branch, as well as the following, from oldest to newest commit:

  • branch1 (not merged into master)
  • branch2 (merged)
  • branch3 (not merged)

I am able to get each of these lists separately... e.g. to get all the branches not merged into master:

$ git branch -r --no-merged origin/master
origin/branch1
origin/branch3

Or to get the top fifteen branches, ordered by most recent commit (via https://coderwall.com/p/ndinba):

$ git for-each-ref --sort=-committerdate --format='%(committerdate:short) %(refname:short)' --count=15 refs/remotes/origin/
2013-03-22 origin/branch3
2013-03-22 origin/branch2
2013-03-22 origin/master
2013-03-22 origin/branch1

So I basically want that second list, minus branch2 (with or without master). Hope that makes sense?

like image 749
Aidan Feldman Avatar asked Mar 22 '13 18:03

Aidan Feldman


1 Answers

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.

like image 90
spitzanator Avatar answered Oct 25 '22 01:10

spitzanator