URL: https://github.com/peterbe/gg2

10 years ago I wrote a command line tool called gg, in Python, that helps me with git branches. Now I've rewritten it from scratch in TypeScript. The new tool is called gg2 and it's available on https://github.com/peterbe/gg2. It's written in Bun and it's sleek.

For one thing, it's fast. For example, running gg --version takes "25.0 ms ± 0.7 ms" on average. That's actually faster than the GitHub CLI gh (by a small margin). The reason it's fast is because it's compiled as a binary executable specifically for your OS. The code is entirely written in TypeScript and uses the commander package.

What it does

The most important feature is gg start which will ask you for a title. This title will be used to create a new branch with an appropriate name. For example, if the title is "Fix for crashing Donkey" will create a branch (in my case) called peterbe/fix-for-crashing-donkey. Then, when you're done and ready to commit, you type gg commit and that will use that typed in title as the default commit message, ask about any not-yet-added files, push to the origin, and make a clickable link to create the GitHub PR.

If you run gg github token you can supply a GitHub personal access token and now you can type gg pr to get information about the current state of the PR associated with the current branch. Tip: gg pr --watch is useful when you've enabled auto-merge.

Then, when you're done with a branch and it has been merged into the default branch (on the origin) you can type gg getback which will take care of taking you branch to the default branch and delete the topic branch that was merged.

Another useful command is gg branches which will list recently worked on branches with some information about each branch. What's neat is that you can fuzzy search to filter. And if exactly 1 branch is found, you just have to hit Enter to switch to that branch.

gg branches

gg branches fuzzy finder

Something I often use is gg mainbranch (or its alias gg mastermerge). What that does is it fetches the upstream default branch and merges that in. That's faster than having to type something like this:


git checkout master
git pull origin master
git checkout -
git merge master

Installation

At the moment, if you're using Linux you can just download of the compiled releases for your operating system and put it into your $PATH. For example:

wget https://github.com/peterbe/gg2/releases/download/v0.0.7/gg-linux-x64
mv gg-linux-x64 /usr/bin/gg
chmod +x /usr/bin/gg

For macOS, I haven't figured that out, yet. If you download a file like https://github.com/peterbe/gg2/releases/download/v0.0.7/gg-darwin-arm64, macOS won't allow you to execute it because it hasn't been signed and certified. To solve that, I think I need to figure out how to make a Homebrew formula. I'd love some help.

But the simplest way is to have bun installed on your system and manually compile it. Something like this should work:


git clone https://github.com/peterbe/gg2.git && cd gg2
bun install
bun run build
cp out/gg ~/bin
chmod +x ~/bin/gg

The future

In a sense, this tool is quite "selfish". I'm taking tedious uses of git and wrapping them in conveniences. After all, it's just a thin convenience over git. It does not replace git.

It would be nice to figure out how to expose this as a Homebrew formula so other people can easily install and benefit too. It's something I have no experience with at the moment.

Features can added incrementally based on "Gosh! This is getting tedious and it's something I often have to do."
At my current work, we use Jira for tickets and GitHub for pull requests. It would be nice to be able to just type gg start 1234 and that would extract the Jira ticket title as a default suggestion.

Do you have thoughts and ideas that would help you? Let me know. It's fun to collaborate!

Comments

Your email will never ever be published.

Previous:
Bot traffic hitting my blog July 9, 2025 This site, Web development
Related by category:
Parse a CSV file with Bun September 13, 2023 Bun
Switching from Next.js to Vite + wouter July 28, 2023 JavaScript
Video to screenshots app June 21, 2025 Bun, JavaScript
An ideal pattern to combine React Router with TanStack Query November 18, 2024 JavaScript
Related by keyword:
How to resolve a git conflict in poetry.lock February 7, 2020 Python
Use vars() to send an argparse Namespace into a function in Python January 8, 2019 Python
How to get all of MDN Web Docs running locally June 9, 2021 Web development, MDN
How to unset aliases set by Oh My Zsh June 14, 2018 Linux, macOS