{"record":{"id":"f2a4fdb69387f673","repo":"jesseduffield/lazygit","slug":"cannot-exclude-gitignore","errorCode":null,"errorMessage":"Cannot exclude .gitignore","messagePattern":"Cannot exclude \\.gitignore","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"pkg/gui/controllers/files_controller.go","lineNumber":1028,"sourceCode":"\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},\n\t\t\t\tOnPress: func() error {\n\t\t\t\t\tif err := self.ignore(node); err != nil {\n\t\t\t\t\t\treturn err\n\t\t\t\t\t}\n\t\t\t\t\treturn nil\n\t\t\t\t},\n\t\t\t\tKeys: menuKey('i'),","sourceCodeStart":1010,"sourceCodeEnd":1046,"githubUrl":"https://github.com/jesseduffield/lazygit/blob/c477a2959b229fbf3284be0d4d2904ab61ec3c94/pkg/gui/controllers/files_controller.go#L1010-L1046","documentation":"Thrown by FilesController.exclude when the selected node's path is exactly '.gitignore'. Excluding means adding a rule to .git/.gitignore (lazygit's exclude file); excluding .gitignore itself would hide it from the files panel and make future ignore/exclude edits invisible to the user, so it is blocked. Mirror of the ignore-side guard with its own message key (ExcludeGitIgnoreErr).","triggerScenarios":"Choosing 'exclude' from the ignore/exclude menu (or the exclude keybinding) while .gitignore is the selected file.","commonSituations":"Same as the ignore case: .gitignore selected in the files panel and the user reaches for exclude instead of ignore, often not realizing which file is highlighted.","solutions":["Select the file you want permanently ignored and exclude that instead","If .gitignore clutters your view, filter it with lazygit's filter ( '/') rather than excluding it"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Guard exclude the same way as ignore:\nif node.GetPath() == \".gitignore\" {\n    return errors.New(\"refusing to exclude .gitignore\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never add .gitignore to .git/info/exclude","Use view filters instead of exclusion to hide config files","Apply the same self-reference guard to any new ignore/exclude entry points"],"tags":["git","gitignore","exclude","self-reference-guard"],"backgroundTag":null,"analyzedSha":"c477a2959b229fbf3284be0d4d2904ab61ec3c94","analyzedAt":"2026-08-15T08:34:32.451Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}