Skip to content

Instantly share code, notes, and snippets.

@lox
Created October 13, 2009 23:50
Show Gist options
  • Save lox/209677 to your computer and use it in GitHub Desktop.
Save lox/209677 to your computer and use it in GitHub Desktop.
git-recent-branches
#!/usr/bin/env php
<?php
## git-recent-branches: shows all branches, sorted by the most recently updated
## git-recent-branches Copyright 2009 Lachlan Donald <lachlan@ljd.cc>.
$verbose = in_array('-v',$argv);
$arg = in_array('-a',$argv) ? '-a' : '';
$branches = array();
// build list of branches
foreach(explode("\n",`git branch $arg -v`) as $branchline)
{
if($tokens = array_filter(preg_split("/\s+/",trim($branchline,' *'),3)))
{
$tokens[] = trim(`git show --pretty=format:"%ct" $tokens[1] | head -n1`);
$branches[] = $tokens;
}
}
// sort by timestamp
usort($branches, create_function('$a,$b','return strcmp($b[3], $a[3]);'));
// print out
foreach($branches as $branch)
{
if($verbose)
{
printf(" %-50s %s %s %s\n", $branch[0], $branch[1], date('Y-m-d', $branch[3]), $branch[2]);
}
else
{
printf(" %-50s\n", $branch[0]);
}
}
// and llamas...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment