{"record":{"id":"3381fc14ed4f5542","repo":"jesseduffield/lazygit","slug":"you-cannot-remove-the-current-worktree","errorCode":null,"errorMessage":"You cannot remove the current worktree!","messagePattern":"You cannot remove the current worktree!","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/gui/controllers/worktrees_controller.go","lineNumber":131,"sourceCode":"\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\n\tdetachedReason := &types.DisabledReason{Text: self.c.Tr.WorktreeNotCheckedOutOnBranch}\n\n\tremoveWorktreeAndBranchItem := &types.MenuItem{\n\t\tLabel: self.c.Tr.RemoveWorktreeAndDeleteBranch,","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/jesseduffield/lazygit/blob/c477a2959b229fbf3284be0d4d2904ab61ec3c94/pkg/gui/controllers/worktrees_controller.go#L113-L149","documentation":"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.","triggerScenarios":"Pressing remove on the worktrees-panel entry matching the worktree lazygit was launched in (IsCurrent flag set on the model).","commonSituations":"User opens lazygit inside a scratch worktree and later wants it gone; forgetting which worktree the session belongs to.","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."],"exampleFix":"# before\n$ # inside wt-feature, remove wt-feature in lazygit -> error\n\n# after\n$ cd /path/to/repo-main\ngit worktree remove ../wt-feature","handlingStrategy":"validation","validationCode":"if worktree.IsCurrent {\n    // disable the remove action; instruct user to remove from another worktree\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["git","worktree","self-deletion-guard"],"backgroundTag":null,"analyzedSha":"c477a2959b229fbf3284be0d4d2904ab61ec3c94","analyzedAt":"2026-08-15T08:34:32.451Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}