In both my work and personal coding projects, I generally have a number of various branches going at once. Switching between various branches (or remembering past things I was working on) can somethings be a chore. Especially if I’m not diligent about deleting branches that have already been merged.
Usually, I do something like:
> git branch
Then, I get a ridiculously huge list of branches that I’ve forgotten to prune and spend all sorts of time trying to remember what I was most recently working on.
daves/XXXX-123/enable-clickstream daves/XXXX-123/impression-events daves/XXXX-123/tracking-fixes daves/XXXX-123/broken-hdps daves/XXXX-123/fix-contacts daves/XXXX-123/listing-provider daves/XXXX-123/revert-listing-wrapper-classname daves/XXXX-123/typescript-models daves/XXXX-123/inline-contact-form daves/XXXX-123/clickstream_application_event daves/XXXX-123/unused-file daves/XXXX-123/convert-typescript daves/XXXX-123/convert-typescript-v2 daves/XXXX-123/similar-impressions daves/XXXX-123/update-node-version
At least 75% of those have already been merged and should have been pruned.
There has to be a better way, right?
Thanks to the power of the Google machine (and Stack Overflow), I found out, there is!
> git branch --sort=-committerdate
Hot diggity dog!
daves/XXXX-123/clickstream-filter-events main daves/XXXX-123/convert-typescript-v2 daves/XXXX-123/update-node-version daves/XXXX-123/similar-impressions daves/XXXX-123/convert-typescript daves/XXXX-123/clickstream_application_event daves/XXXX-123/unused-file daves/XXXX-123/typescript-models daves/XXXX-123/listing-provider daves/XXXX-123/inline-contact-form daves/XXXX-123/revert-listing-wrapper-classname
That list is now sorted by most recent activity on the branch.
Alright. Even though this is better, that’s still a lot of typing to remember. Fortunately, we can create an alias:
> git config --global alias.recent "branch --sort=-committerdate"
Now all I need to do is just type git recent
and it works!
Nice.