Skip to content

Instantly share code, notes, and snippets.

@nhusher
Last active August 29, 2015 13:56
Show Gist options
  • Save nhusher/9038904 to your computer and use it in GitHub Desktop.
Save nhusher/9038904 to your computer and use it in GitHub Desktop.
This script lists all the branches in the repo that have been merged into master and their last-modified date, along with the author of the last modification. Useful for tracking down stale feature branches that aren't being actively developed.
git branch -a --merged master | grep remotes\/ | sed 's/^[ \t]*//' | xargs -n 1 git log --pretty=format:"%an - %d - %ar %n" -1 | sort | cat
git branch -a | grep -v master | grep remotes\/ | sed 's/^[ \t]*//' | xargs -n 1 git log --pretty=format:"%an - %d - %ar %n" -1 | sort | cat
git branch -a --merged master

Remove all references to master.

grep -v master

Get all branches that have been merged into master.

grep remotes\/

Remove any local branches, we only care about what branches exist in origin.

sed 's/^[ \t]*//'

Strip leading whitespace.

xargs -n 1 git log --pretty=format:"%an - %d - %ar %n" -1

For each branch returned by git branch -a --merged master that pass the grep, get the first commit from each branch in the format {{AUTHOR_NAME}} - {{BRANCH_NAME}} - {{LAST_COMMIT}} where LAST_COMMIT is relative to the current date.

 sort | cat

Sort the results by author name, and hold the results until they all come back.

The result looks something like this:

John Doe - (origin/hotfix/1.8.1) - 9 weeks ago 
Jane Doe - (origin/some-old-feature) - 2 years ago 
Jane Doe - (origin/another-old-feature) - 1 year, 8 months ago 
Jane Doe - (origin/some-recent-feature) - 3 days ago 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment