Skip to content

Instantly share code, notes, and snippets.

@thetristan
Created May 23, 2012 23:17
Show Gist options
  • Save thetristan/2778445 to your computer and use it in GitHub Desktop.
Save thetristan/2778445 to your computer and use it in GitHub Desktop.
Quick shell script to check the freshness of your git branches
#!/bin/bash
# ## git-fresh
#
# Author: Tristan Blease <[email protected]>
# Website: tristanblease.com
# License: http://www.opensource.org/licenses/MIT
#
# Quick shell script to check the freshness of your git repository branches
#
# Place this script somewhere in your PATH and make it executable
# This script can then be ran within any git repository by calling
# `git fresh` within the repository
#
# Example usage:
#
# $ cd path/to/my/git/repo
# $ git fresh
#
# Output:
#
# Branch name Last commit dated
# ----------- -----------------
# topic_branch_a 2012-06-15 16:39:42 -0500
# develop 2012-06-12 17:11:17 -0500
# master 2012-06-12 10:25:36 -0500
# topic_branch_c 2012-06-07 10:33:24 -0500
# topic_branch_b 2012-05-24 16:20:00 -0500
#
function get_branch_data() {
(
for b in `git branch | sed 's:^[ *]*::'`; do
git log -n 1 $b --pretty="format:%ct|%ci" -- |
sed "s^\(.*\)|\(.*\)$^\1|${b}|\2^"
done
)
}
get_branch_data |
sort -k 1gr |
sed "s:^\([0-9]*|\)\(.*\):\2:" |
sed -e '1 i\' -e '1 i\
Branch name|Last commit dated' -e '1 i\
-----------|-----------------' |
column -t -s '|'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment