{"record":{"id":"34f1c74e1ff25f1f","repo":"jesseduffield/lazygit","slug":"cannot-ignore-gitignore","errorCode":null,"errorMessage":"Cannot ignore .gitignore","messagePattern":"Cannot ignore \\.gitignore","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"pkg/gui/controllers/files_controller.go","lineNumber":1021,"sourceCode":"\nfunc (self *FilesController) ignoreOrExcludeFile(node *filetree.FileNode, trText string, trPrompt string, trAction string, f func(string) error) error {\n\tif node.GetIsTracked() {\n\t\tself.c.Confirm(types.ConfirmOpts{\n\t\t\tTitle:  trText,\n\t\t\tPrompt: trPrompt,\n\t\t\tHandleConfirm: func() error {\n\t\t\t\treturn self.ignoreOrExcludeTracked(node, trAction, f)\n\t\t\t},\n\t\t})\n\n\t\treturn nil\n\t}\n\treturn self.ignoreOrExcludeUntracked(node, trAction, f)\n}\n\nfunc (self *FilesController) ignore(node *filetree.FileNode) error {\n\tif node.GetPath() == \".gitignore\" {\n\t\treturn errors.New(self.c.Tr.Actions.IgnoreFileErr)\n\t}\n\treturn self.ignoreOrExcludeFile(node, self.c.Tr.IgnoreTracked, self.c.Tr.IgnoreTrackedPrompt, self.c.Tr.Actions.IgnoreExcludeFile, self.c.Git().WorkingTree.Ignore)\n}\n\nfunc (self *FilesController) exclude(node *filetree.FileNode) error {\n\tif node.GetPath() == \".gitignore\" {\n\t\treturn errors.New(self.c.Tr.Actions.ExcludeGitIgnoreErr)\n\t}\n\n\treturn self.ignoreOrExcludeFile(node, self.c.Tr.ExcludeTracked, self.c.Tr.ExcludeTrackedPrompt, self.c.Tr.Actions.ExcludeFile, self.c.Git().WorkingTree.Exclude)\n}\n\nfunc (self *FilesController) ignoreOrExcludeMenu(node *filetree.FileNode) error {\n\treturn self.c.Menu(types.CreateMenuOptions{\n\t\tTitle: self.c.Tr.Actions.IgnoreExcludeFile,\n\t\tItems: []*types.MenuItem{\n\t\t\t{\n\t\t\t\tLabelColumns: []string{self.c.Tr.IgnoreFile},","sourceCodeStart":1003,"sourceCodeEnd":1039,"githubUrl":"https://github.com/jesseduffield/lazygit/blob/c477a2959b229fbf3284be0d4d2904ab61ec3c94/pkg/gui/controllers/files_controller.go#L1003-L1039","documentation":"Thrown by FilesController.ignore when the selected node's path is exactly '.gitignore'. Adding .gitignore to itself would make git stop tracking the very file that governs ignoring — and the ignore action appends a rule to .gitignore, so ignoring it is self-defeating. lazygit special-cases the path and refuses.","triggerScenarios":"Pressing the ignore key ('i' or via the ignore/exclude menu, 'g' menu) while the .gitignore file itself is selected in the files panel.","commonSituations":"Users selecting .gitignore to inspect it and hitting the ignore key, or muscle-memory 'i' while scrolling an untracked-files list containing .gitignore.","solutions":["Deselect .gitignore and ignore the file you actually meant","If you truly want .gitignore untracked, remove it from the index manually: 'git rm --cached .gitignore'"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Guard the self-referential case before ignoring:\nif node.GetPath() == \".gitignore\" {\n    return errors.New(\"refusing to ignore .gitignore itself\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Skip .gitignore in ignore-action handlers","Use 'git rm --cached .gitignore' if untracking is genuinely intended","Keep ignore rules targeting content files, never the ignore file itself"],"tags":["git","gitignore","self-reference-guard","files-panel"],"backgroundTag":null,"analyzedSha":"c477a2959b229fbf3284be0d4d2904ab61ec3c94","analyzedAt":"2026-08-15T08:34:32.451Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}