Lazygit and Git Worktree
Lazygit is a terminal UI for Git that includes first-class git worktree support. Its dedicated Worktrees tab lets you create, switch between, and remove worktrees entirely through a keyboard-driven interface. If you prefer working in the terminal but want more visual feedback than raw Git commands, Lazygit is one of the best tools for managing worktrees.
The Lazygit Worktree Tab
Lazygit organizes its interface into tabs: Status, Files, Branches, Commits, Stash, and — when worktrees exist — a Worktrees tab. This tab lists all linked worktrees along with their paths and checked-out branches.
To access the Worktrees tab, press the number key shown in the tab bar or cycle through tabs with [ and ]. The tab appears automatically when your repository has linked worktrees. If you have no linked worktrees yet, you can still access worktree creation from the Branches tab.
# Install Lazygit (if not already installed)
# macOS
brew install lazygit
# Ubuntu / Debian (via apt repository)
sudo add-apt-repository ppa:lazygit-team/release
sudo apt-get update
sudo apt-get install lazygit
# Arch Linux
pacman -S lazygit
# Go install
go install github.com/jesseduffield/lazygit@latestCreating Worktrees in Lazygit
There are two ways to create worktrees in Lazygit:
From the Branches Tab
Navigate to the Branches tab, highlight the branch you want to check out, and press w to open the worktree menu. Select "Create worktree from branch" and enter the path for the new worktree directory. Lazygit will run git worktree add for you.
From the Worktrees Tab
If you are already in the Worktrees tab, press n to create a new worktree. Lazygit prompts you for the branch name and path. You can create a worktree from an existing branch or create a new branch in the process.
# What Lazygit runs behind the scenes:
# Creating a worktree for an existing branch
git worktree add ../my-project-feature feature/my-feature
# Creating a worktree with a new branch
git worktree add -b feature/new-work ../my-project-new-work mainSwitching Between Worktrees
In the Worktrees tab, highlight the worktree you want to switch to and press Enter. Lazygit will change its working directory to that worktree and refresh the entire UI to reflect the new context — files, branches, commits, and stash all update to show the state of the selected worktree.
This is one of Lazygit's most powerful worktree features. Instead of closing Lazygit, changing directories, and relaunching, you stay in the same TUI session and jump between worktrees instantly. Your scroll positions and UI state in other tabs reset, but the transition is seamless.
# Lazygit worktree switching workflow:
# 1. Open Lazygit in any worktree
lazygit
# 2. Navigate to the Worktrees tab (press the tab number or use [ ])
# 3. Highlight the desired worktree with j/k
# 4. Press Enter to switch
# 5. The entire Lazygit UI refreshes to show the new worktree contextRemoving Worktrees
To remove a worktree, navigate to the Worktrees tab, highlight the worktree you want to delete, and press d. Lazygit will ask for confirmation before running git worktree remove.
If the worktree has uncommitted changes, Lazygit will warn you and offer to force-remove it. You can also press D (shift+d) to force-remove without the initial check.
Note: you cannot remove the worktree you are currently viewing. Switch to a different worktree first, then remove the one you no longer need.
Keyboard Shortcuts Reference
| Key | Context | Action |
|---|---|---|
| w | Branches tab | Open worktree menu for selected branch |
| n | Worktrees tab | Create a new worktree |
| Enter | Worktrees tab | Switch to highlighted worktree |
| d | Worktrees tab | Remove worktree (with confirmation) |
| D | Worktrees tab | Force remove worktree |
| [ ] | Any tab | Cycle between tabs |
Configuration
Lazygit's worktree behavior can be customized through its config file. The config file is located at ~/.config/lazygit/config.yml on Linux/macOS.
# ~/.config/lazygit/config.yml
# Show worktrees tab even when there are no linked worktrees
gui:
showWorktreesTab: true
# Custom keybindings for worktree operations
keybinding:
worktrees:
createWorktree: "n"
removeWorktree: "d"
forceRemoveWorktree: "D"
# Skip confirmation when switching worktrees
notARepository: "skip"You can also set up custom commands in Lazygit to combine worktree creation with other actions, like running npm install after creating a worktree for a Node.js project:
# Custom command in config.yml
customCommands:
- key: "W"
context: "localBranches"
command: >
git worktree add ../{{.SelectedLocalBranch.Name}}
{{.SelectedLocalBranch.Name}} &&
cd ../{{.SelectedLocalBranch.Name}} &&
npm install
description: "Create worktree and install dependencies"
subprocess: true