There is git branch -r to list all remote branches.
I wonder if there is away to list all remote branches, but order them by number of commits (eg., the branch with most commits is listed first).
I guess one usage is that it can filter out unused/obsolete branches (that have very commits) and tidy up the repo
That is what you see in the "branches" tab section of a GitHub project:
Example for git/git/branches:
What you want is not the number of commits, but, for a given branch acting as reference, the number of commit ahead and behind that branch.
git rev-list --left-right --count master...test-branch That way you can see the one behind that could be safely removed.
Note that you can already list those merged branches with:
git branch --merged master With Git 2.5, you can also list local branches compared to their remote tracking branches (not your case, but can be useful):
git fetch git for-each-ref --format="%(push:track)" refs/heads --count could be combined with --left-right to count the left and right sides of the symmetric difference!%(push:track), there should be a shorthand for that kind of behind/ahead display between two branches.@{u}, and it's git status :-) The @{upstream} syntax is not very pretty, but the only alternative I know of is Mercurial's generalized expression parser, which is heavy-weight. It has great power, but with shell vagaries requiring quoting, it's pretty klunky syntactically too.
git branchas you'd like, but as a step in the right direction this is how you can determine how many commits are on each branchgit for-each-ref,git rev-list --count, and thesortprogram. The result would not be very useful though as the count of commits on a branch is hardly ever worthwhile: a new branch, just created right now frommaster, has every commit thatmasterhas. (You probably want to redefine "how many commits" as something like "how many unique commits", perhaps.)git rev-list --count X..Y(two dots rather than three):X..YmeansY ^Xwhich means "the set of all commits onYminus the set of all commits onX" (i.e., set subtraction), and--countthen counts the number of elements in that set. HereYis the branch you want to count, but you must also name some other branchX, otherwise in a typical repository with tens of thousands of commits, you will find tens of thousands of commits on every branch.