I'll often use branches to try out experiments, ideas, and to separate different trains of thought. Not every branch gets merged – in fact, it's quite common for me to make several commits on a branch, look at the end result, and throw the branch away without ever merging it (branching is cheap and ideas are cheap, but bad code is expensive). As a result, I can end up with a lot of branches. This makes the output of git branch
difficult to sort through:
$ git branch
* account-org-association
acdx-blog-posts
add-static-resource-support
alter-component-naming
changeset-details-in-org-migration
checkable-categories
client-soap
client-time-zone
comments-url-in-org-migration-json
comparison-cache-env
…another 70+ more…
When I'm listing my branches, I want to see an indication of freshness. Which branches have I worked on recently, and what did I last do on it?
Introducing freshness
:
$ git freshness
* account-org-association 75 minutes ago Link orgs directly to accounts
notification-settings 2 hours ago WIP
make-changes-default 12 days ago Make migrations redirect to changes after creation
staging 12 days ago Display a list of components during the review phase
master 3 weeks ago Add migration target labels for source and destination
project-ordering 4 weeks ago Sort project names in nav
checkable-categories 4 weeks ago Allow a user to bulk-select a type of metadata
search 4 weeks ago Support search in comparisons
refactor-selectable-component 4 weeks ago Refactor SelectableComponent
fix/intermittent-failing-spec 8 weeks ago Explicitly specify Salesforce type in specs
…etc.…
This lists the branches by most recently changed first, including how long ago the branch was changed and what the last commit message was. I often pipe this to head
to pull up a list of the most recent branches I've worked on.
To use it, edit your ~/.gitconfig
and add the following to the [alias]
section:
freshness = "!f() { git for-each-ref --sort=-committerdate refs/heads/ --format='%(HEAD) %(color:cyan)%(refname:short)%(color:reset) | %(committerdate:relative)%(color:reset) | %(subject)' | column -s '|' -t; }; f"
👍 looks good! added that today