How to show which Git branches have changed recently
Robert Rees

Robert Rees @rrees

Location:
London, United Kingdom
Joined:
Jan 27, 2019

How to show which Git branches have changed recently

Publish Date: Aug 30 '21
5 1

I will admit to some bad working habits, one of them is working on multiple things at the same time rather trying to focus exclusively on one unit of work and completing it before I move on to the next thing. This means that I sometimes have multiple Github branches that I'm working on for a repository. Unfortunately this intersects with another bad habit I have of not cleaning up my local branches frequently. The two combined mean that when I'm slicing between tasks I often find it difficult to find the branch I was working on before I switched tasks.

Enter Git sorts to save me!

By default Git sorts branches lexically but using the committerdate sort you instead get the branches from the most recently committed to the last commit date.

Git sorts can also be reversed by putting the minus sign before the sort name.

This effectively brings back the branches in the order you last changed them.

To summarise then:

git branch --sort=-committerdate
Enter fullscreen mode Exit fullscreen mode

Allows you to see which branches you changed most recently in a repository.

Comments 1 total

  • Peter Benjamin (they/them)
    Peter Benjamin (they/them)Aug 30, 2021

    Nice tip!

    I have this alias in my ~/.gitconfig:

    [alias]
      branches = branch -a --sort=-committerdate
    
    Enter fullscreen mode Exit fullscreen mode

    Allows me to type git branches on a repo and get all branches sorted by most recent commit.

Add comment