gg2 is a command line tool for doing things with Git branches, faster. One of the convenient commands is gg2 branches. It lists your recent branches, sorted by committer-date and for each branch it displays a human-friendly date distance and whether it's already been merged. Looks like this:

Turns out, for large repos figuring out which branches have already been merged is quite slow. For example, in this repo it takes half a second to list all merged branches:


$ git branch --all --merged | wc -l
669

$ time git branch --all --merged 1>/dev/null

real    0m0.490s
user    0m0.460s
sys     0m0.030s

The problem was that gg2 branches also does multiple other git branch listing commands to get information. In particular: get the current branch, figure out the default branch, a list of branch committer dates, and a list of merged branches.
All of these async operations were done in serial. With a bit of rearranging, and refactoring, all of these can be turned into this:


const [defaultBranch, currentBranch, dates, isMerged] = await Promise.all([
  getDefaultBranch(git),
  getCurrentBranch(git),
  getAllBranchDates(git),
  getAllMergedBranches(git),
])

The getAllMergedBranches(git) function still takes a very long time and I think it lists all remote branches that have been merged. Anyway, now it's only the slowest part of the Promise.all rather than one of multiple.

Comments

Your email will never ever be published.

Previous:
xbar-my-prs Info about your GitHub PRs in the macOS menu bar January 29, 2026 Bun, macOS, TypeScript
Related by category:
Bun vs. Go for a basic web server benchmark October 24, 2025 Bun
Benchmarking oxlint vs biome December 12, 2025 Bun, TypeScript
Hosting your static web site with Firebase Hosting November 3, 2025 Bun
Testing out vite 8 on SPA: Vite 8 is 5x faster December 6, 2025 Bun, TypeScript
Related by keyword:
Optimizing Bun compiled binary for gg2 January 13, 2026 Bun, TypeScript
gg commit with suggested --no-verify August 29, 2025 Bun
gg2 is now installable with Homebrew December 8, 2025 Bun, TypeScript
How I end-to-end test my Bun CLI app September 18, 2025 Bun