← Retour au blog
tech 31 August 2026

Sort Git Branches by Last Commit Date

Discover how to optimize your Git workflow by sorting branches by the last commit date. A significant time saver for busy developers.

Article inspired by the original source
Sort branches by last commit date ↗ ryangreenberg.com

Introduction

As a developer, you probably spend a lot of time managing your Git branches. With many ongoing projects, it's easy to get lost in a sea of branches. Fortunately, Git offers a straightforward solution to sort these branches by the last commit date, allowing you to focus on what truly matters.

Why Sort by Last Commit Date?

Sorting branches by the last commit date may seem trivial, but it has several benefits. Firstly, it allows you to quickly identify active branches that need immediate attention. Secondly, it helps keep your repository clean and organized by encouraging you to delete or merge obsolete branches.

The Traditional Method

Historically, many developers used custom scripts to sort branches. A classic example is using the following command:

``bash function branches { for k in git branch | sed "s/^..//"; do echo -e git log --color -1 --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" "$k"\t"$k"; done | sort } ``

This method works but is far from optimal, especially with modern versions of Git.

The Modern Solution

With recent versions of Git, you can directly configure the git branch command to sort by last commit date. Here's how:

``bash git config branch.sort committerdate ``

For one-off usage, you can also use:

``bash git branch --sort committerdate ``

Other Sorting Options

Git allows you to sort branches according to different criteria. For example:

  • authordate: sorts by the author's commit date.
  • creatordate: sorts by the branch's creation date.

These options can be useful in specific contexts where you want to analyze branches from another angle.

Use Case

Consider a development team working on a SaaS application with a continuous delivery cadence. By sorting branches by last commit date, the team can easily identify features under active development, optimize code reviews, and prioritize testing.

Conclusion

Optimizing Git branch management is essential for any modern development team. By using Git's native capabilities to sort branches, you save time and reduce workflow complexity. This allows you to focus on what truly matters: writing quality code.

Let's discuss your project in 15 minutes.

Git branches commit date workflow optimization development
Deepthix newsletter · 100% AI · every Monday 8am

An AI agent reads tech for you.

Our AI agent scans ~200 sources per week and ships the best articles to your inbox Monday 8am. Free. One click to unsubscribe.

Visit the newsletter page →

Want to automate your operations?

Let's talk about your project in 15 minutes.

Book a call