{"record":{"id":"7e1274c3bf074da3","repo":"jesseduffield/lazygit","slug":"you-cannot-remove-the-main-worktree","errorCode":null,"errorMessage":"You cannot remove the main worktree!","messagePattern":"You cannot remove the main worktree!","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/gui/controllers/worktrees_controller.go","lineNumber":127,"sourceCode":"\t\t}\n\n\t\tself.c.RenderToMainViews(types.RefreshMainOpts{\n\t\t\tPair: self.c.MainViewPairs().Normal,\n\t\t\tMain: &types.ViewUpdateOpts{\n\t\t\t\tTitle: self.c.Tr.WorktreeTitle,\n\t\t\t\tTask:  task,\n\t\t\t},\n\t\t})\n\t}\n}\n\nfunc (self *WorktreesController) add() error {\n\treturn self.c.Helpers().Worktree.NewWorktree()\n}\n\nfunc (self *WorktreesController) remove(worktree *models.Worktree) error {\n\tif worktree.IsMain {\n\t\treturn errors.New(self.c.Tr.CantDeleteMainWorktree)\n\t}\n\n\tif worktree.IsCurrent {\n\t\treturn errors.New(self.c.Tr.CantDeleteCurrentWorktree)\n\t}\n\n\tremoveWorktreeItem := &types.MenuItem{\n\t\tLabel: self.c.Tr.RemoveWorktree,\n\t\tKeys:  menuKey('w'),\n\t\tOnPress: func() error {\n\t\t\treturn self.c.Helpers().Worktree.Remove(worktree, nil)\n\t\t},\n\t}\n\n\tbranch, branchFound := lo.Find(self.c.Model().Branches, func(branch *models.Branch) bool {\n\t\treturn branch.Name == worktree.Branch\n\t})\n\t// A worktree with a detached HEAD has no branch to delete","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/jesseduffield/lazygit/blob/c477a2959b229fbf3284be0d4d2904ab61ec3c94/pkg/gui/controllers/worktrees_controller.go#L109-L145","documentation":"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.","triggerScenarios":"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).","commonSituations":"User wants to delete 'everything' and selects the first/main entry; unfamiliarity with which entry is main; cleanup scripts iterating all worktrees.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if worktree.IsMain {\n    // hide or disable the remove action for the main worktree\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["git","worktree","main-worktree","guard"],"backgroundTag":null,"analyzedSha":"c477a2959b229fbf3284be0d4d2904ab61ec3c94","analyzedAt":"2026-08-15T08:34:32.451Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}