Lazygit: The terminal UI that makes git actually usable
I have a confession. I’ve been using git for over a decade, and I still forget the syntax for interactive rebase. Every. Single. Time.
That’s why I started using Lazygit. It’s a terminal UI for git commands built in Go. It turns complex git operations into simple keystrokes.
What is Lazygit?
Lazygit is a CLI tool that provides a visual interface for git right in your terminal. No more switching between your editor and a GUI app. No more Googling “git rebase onto” for the hundredth time.
You run lazygit in any git repo. You get a panel-based interface showing your files, branches, commits, and stash. Everything you need in one place.
The tool is written entirely in Go. This makes it fast, portable, and easy to install. A single binary with no dependencies.
Why Go is Perfect for CLI Tools
Go has become the go-to language for CLI tools. And Lazygit shows why.
The binary compiles to a single executable. No runtime needed. No dependency hell. Just download and run.
Go’s cross-compilation makes distribution simple. Build for Linux, macOS, and Windows from one machine. Lazygit supports all three.
The startup time is instant. Go binaries launch in milliseconds. Compare that to Python or Node-based CLIs that need to spin up an interpreter.
If you’re building CLI tools, check out Cobra and Bubble Tea. Lazygit uses a custom TUI approach, but these libraries power many popular Go CLIs.
Getting Started with Lazygit
Installation is straightforward. On macOS with Homebrew:
brew install lazygit
On most Linux distros, use your package manager or download the binary directly from GitHub releases.
Once installed, navigate to any git repo and run:
lazygit
You’ll see something like this layout:
- Left panel: Status, files, branches, commits, stash
- Right panel: Diffs and details
- Bottom: Command feedback
The keybindings are intuitive. Press ? for help at any time.
Common Operations Made Simple
Here’s where Lazygit shines. Operations that require multiple commands become single keystrokes.
Interactive rebase:
Navigate to a commit. Press e to edit. Press d to drop. Press s to squash. Done.
Cherry-pick commits:
Press c on commits you want. Switch to the target branch. Press v to paste.
Resolve merge conflicts:
Lazygit shows conflicts inline. Press b to pick “both”. Press < or > to pick one side.
Stage individual lines:
Press enter on a file to see the diff. Use arrow keys to select lines. Press space to stage just those lines.
This is similar to how we handle complex operations in Go code. We break them into smaller, manageable pieces. If you’ve worked with regex in Go, you know how helpful visual feedback can be when debugging patterns.
Customizing Lazygit
Lazygit reads its config from ~/.config/lazygit/config.yml. Here’s a useful starter config:
gui:
theme:
selectedLineBgColor:
- reverse
selectedRangeBgColor:
- reverse
showIcons: true
nerdFontsVersion: "3"
git:
paging:
colorArg: always
pager: delta --dark --paging=never
commit:
signOff: true
keybinding:
universal:
quit: 'q'
return: '<esc>'
The pager setting is powerful. You can pipe diffs through delta for syntax highlighting. It transforms the diff view.
Building Your Own TUI in Go
Lazygit’s codebase is worth studying if you want to build terminal UIs. It handles complex state management across multiple panels.
Here’s a simplified example of how you might read user input for a TUI:
package main
import (
"fmt"
"os"
"os/exec"
)
func main() {
// Set terminal to raw mode for single keypress reading
exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run()
exec.Command("stty", "-F", "/dev/tty", "-echo").Run()
defer exec.Command("stty", "-F", "/dev/tty", "echo").Run()
var b []byte = make([]byte, 1)
for {
os.Stdin.Read(b)
fmt.Printf("Key pressed: %s\n", string(b))
if string(b) == "q" {
break
}
}
}
This is a basic example. Real TUI apps use libraries like tcell or tview for proper terminal handling.
For managing internal state, Go’s approach to error handling becomes crucial. TUI apps need robust error states for things like failed git operations.
Tips for Power Users
After using Lazygit daily for a while, here are my favorite tricks:
-
Custom commands: Add project-specific git aliases to your config. Run them with
@. -
Worktrees support: Lazygit handles git worktrees. Manage multiple branches checked out simultaneously.
-
Undo almost anything: Press
zto undo. Lazygit tracks your actions and can reverse them. -
Filtering: Press
/in any panel to filter. Great for finding specific commits or branches. -
Bulk operations: Select multiple items with
v, then act on all of them at once.
Wrapping Up
Lazygit turned git from a frustration into something I actually enjoy using. The visual feedback helps me understand what’s happening. The keyboard shortcuts make me faster.
It’s also a great example of what you can build with Go. A fast, cross-platform CLI tool that solves a real problem.
Give it a try in your next coding session. You might wonder how you lived without it.