Skip to content

Instantly share code, notes, and snippets.

@tomchapin
Created January 31, 2020 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomchapin/dc0d53cbe7e8246955895017163faf48 to your computer and use it in GitHub Desktop.
Save tomchapin/dc0d53cbe7e8246955895017163faf48 to your computer and use it in GitHub Desktop.
This git command lists all branches (local and remote) and orders them by their most recent commit date. Also displays the commit author.
#!/bin/bash
# --------------------------------------------------------------------------
# Git Recent with Details (by Tom Chapin - https://gist.github.com/tomchapin/dc0d53cbe7e8246955895017163faf48)
# -------------------------------------------------------------------------
# One-liner command by estani from this Stack Overflow thread:
# https://stackoverflow.com/questions/5188320/how-can-i-get-a-list-of-git-branches-ordered-by-most-recent-commit
# --------------------------------------------------------------------------
# This git command lists all branches (local and remote) and orders them by
# their most recent commit date. Also displays the commit author.
# --------------------------------------------------------------------------
# Installation:
# Copy this script as a file named "git-recent-details" somewhere in
# your path (For example: /usr/local/bin/git-recent-details), and then
# run "chmod +x git-recent-details" to give it execution permissions.
# --------------------------------------------------------------------------
# Usage:
# From inside your git repo, type "git recent-details"
# --------------------------------------------------------------------------
set -euo pipefail
for ref in $(git for-each-ref --sort=-committerdate --format="%(refname)" refs/heads/ refs/remotes ); do git log -n1 $ref --pretty=format:"%Cgreen%cr%Creset %C(yellow)%d%Creset %C(bold blue)<%an>%Creset%n" | cat ; done | awk '! a[$0]++'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment