jesseduffield/lazygit · warning
You cannot remove the current worktree!
Error message
You cannot remove the current worktree!
What it means
Returned by WorktreesController.remove when worktree.IsCurrent is true — the user tried to remove the worktree lazygit is running in. Deleting the process's own working directory (shell cwd, open files) is unsafe, so it is rejected with a clear message; remove it from a different worktree or the main repo instead.
Source
Thrown at pkg/gui/controllers/worktrees_controller.go:131
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 delete
detachedReason := &types.DisabledReason{Text: self.c.Tr.WorktreeNotCheckedOutOnBranch}
removeWorktreeAndBranchItem := &types.MenuItem{
Label: self.c.Tr.RemoveWorktreeAndDeleteBranch,View on GitHub (pinned to c477a2959b)
Solutions
- Exit lazygit, switch to the main worktree (or another one), and remove it from there.
- Or from outside lazygit: 'git worktree remove <path>' run from any other worktree.
- If the directory must be deleted in place, close all programs using it first and remove it manually.
Example fix
# before $ # inside wt-feature, remove wt-feature in lazygit -> error # after $ cd /path/to/repo-main git worktree remove ../wt-feature
Defensive patterns
Strategy: validation
Validate before calling
if worktree.IsCurrent {
// disable the remove action; instruct user to remove from another worktree
} Prevention
- Disable the remove keybinding via DisabledReason for the IsCurrent row.
- Remove a worktree from a session running in a different worktree.
- From the shell: 'git worktree remove <path>' executed outside that worktree.
When it happens
Trigger: Pressing remove on the worktrees-panel entry matching the worktree lazygit was launched in (IsCurrent flag set on the model).
Common situations: User opens lazygit inside a scratch worktree and later wants it gone; forgetting which worktree the session belongs to.
Related errors
- Lazygit does not support bare repos.
- Branch {{.branchName}} is checked out by worktree {{.worktre
- You are already in the selected worktree
- You cannot remove the main worktree!
- Git version must be at least %s. Please upgrade your git ver
AI-assisted analysis of jesseduffield/lazygit@c477a2959b (2026-08-15).
Data as JSON: /api/errors/3381fc14ed4f5542.
Report an issue: GitHub.