jesseduffield/lazygit · warning
You cannot remove the main worktree!
Error message
You cannot remove the main worktree!
What it means
Returned by WorktreesController.remove when the selected models.Worktree has IsMain == true. The main worktree hosts the repository's .git directory; removing it would destroy the repo, so lazygit refuses unconditionally before even showing the removal menu.
Source
Thrown at pkg/gui/controllers/worktrees_controller.go:127
}
self.c.RenderToMainViews(types.RefreshMainOpts{
Pair: self.c.MainViewPairs().Normal,
Main: &types.ViewUpdateOpts{
Title: self.c.Tr.WorktreeTitle,
Task: task,
},
})
}
}
func (self *WorktreesController) add() error {
return self.c.Helpers().Worktree.NewWorktree()
}
func (self *WorktreesController) remove(worktree *models.Worktree) error {
if worktree.IsMain {
return errors.New(self.c.Tr.CantDeleteMainWorktree)
}
if worktree.IsCurrent {
return errors.New(self.c.Tr.CantDeleteCurrentWorktree)
}
removeWorktreeItem := &types.MenuItem{
Label: self.c.Tr.RemoveWorktree,
Keys: menuKey('w'),
OnPress: func() error {
return self.c.Helpers().Worktree.Remove(worktree, nil)
},
}
branch, branchFound := lo.Find(self.c.Model().Branches, func(branch *models.Branch) bool {
return branch.Name == worktree.Branch
})
// A worktree with a detached HEAD has no branch to deleteView on GitHub (pinned to c477a2959b)
Solutions
- Select a linked worktree instead — the main worktree cannot be removed by design.
- To delete the whole repository, remove the directory from the filesystem outside lazygit.
- If the main worktree entry looks wrong (stale), run 'git worktree prune' and refresh.
Defensive patterns
Strategy: validation
Validate before calling
if worktree.IsMain {
// hide or disable the remove action for the main worktree
} Prevention
- Disable the remove keybinding via DisabledReason for the IsMain row.
- Label the main worktree clearly in the panel so it is not mistaken for a linked one.
- Use 'git worktree remove' from the main repo to delete linked worktrees, never the main one.
When it happens
Trigger: Pressing the remove/delete key on the main worktree entry in the worktrees panel (worktree.IsMain set, typically the entry whose path is the repo root).
Common situations: User wants to delete 'everything' and selects the first/main entry; unfamiliarity with which entry is main; cleanup scripts iterating all worktrees.
Related errors
- Lazygit does not support bare repos.
- Some of the selected branches are checked out by other workt
- Cannot merge branch in detached head state. You might have c
- You cannot merge a branch into itself
- Branch {{.branchName}} is checked out by worktree {{.worktre
AI-assisted analysis of jesseduffield/lazygit@c477a2959b (2026-08-15).
Data as JSON: /api/errors/7e1274c3bf074da3.
Report an issue: GitHub.