jesseduffield/lazygit · info
Cannot exclude .gitignore
Error message
Cannot exclude .gitignore
What it means
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).
Source
Thrown at pkg/gui/controllers/files_controller.go:1028
return self.ignoreOrExcludeTracked(node, trAction, f)
},
})
return nil
}
return self.ignoreOrExcludeUntracked(node, trAction, f)
}
func (self *FilesController) ignore(node *filetree.FileNode) error {
if node.GetPath() == ".gitignore" {
return errors.New(self.c.Tr.Actions.IgnoreFileErr)
}
return self.ignoreOrExcludeFile(node, self.c.Tr.IgnoreTracked, self.c.Tr.IgnoreTrackedPrompt, self.c.Tr.Actions.IgnoreExcludeFile, self.c.Git().WorkingTree.Ignore)
}
func (self *FilesController) exclude(node *filetree.FileNode) error {
if node.GetPath() == ".gitignore" {
return errors.New(self.c.Tr.Actions.ExcludeGitIgnoreErr)
}
return self.ignoreOrExcludeFile(node, self.c.Tr.ExcludeTracked, self.c.Tr.ExcludeTrackedPrompt, self.c.Tr.Actions.ExcludeFile, self.c.Git().WorkingTree.Exclude)
}
func (self *FilesController) ignoreOrExcludeMenu(node *filetree.FileNode) error {
return self.c.Menu(types.CreateMenuOptions{
Title: self.c.Tr.Actions.IgnoreExcludeFile,
Items: []*types.MenuItem{
{
LabelColumns: []string{self.c.Tr.IgnoreFile},
OnPress: func() error {
if err := self.ignore(node); err != nil {
return err
}
return nil
},
Keys: menuKey('i'),View on GitHub (pinned to c477a2959b)
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
Defensive patterns
Strategy: validation
Validate before calling
// Guard exclude the same way as ignore:
if node.GetPath() == ".gitignore" {
return errors.New("refusing to exclude .gitignore")
} Prevention
- 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
When it happens
Trigger: Choosing 'exclude' from the ignore/exclude menu (or the exclude keybinding) while .gitignore is the selected file.
Common situations: 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.
Related errors
- Cannot ignore .gitignore
- Git version must be at least %s. Please upgrade your git ver
- Lazygit does not support bare repos.
- unexpected git output
- Must specify a remote if specifying a branch
AI-assisted analysis of jesseduffield/lazygit@c477a2959b (2026-08-15).
Data as JSON: /api/errors/f2a4fdb69387f673.
Report an issue: GitHub.