jesseduffield/lazygit · info

Cannot ignore .gitignore

Error message

Cannot ignore .gitignore

What it means

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.

Source

Thrown at pkg/gui/controllers/files_controller.go:1021

func (self *FilesController) ignoreOrExcludeFile(node *filetree.FileNode, trText string, trPrompt string, trAction string, f func(string) error) error {
	if node.GetIsTracked() {
		self.c.Confirm(types.ConfirmOpts{
			Title:  trText,
			Prompt: trPrompt,
			HandleConfirm: func() error {
				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},

View on GitHub (pinned to c477a2959b)

Solutions

  1. Deselect .gitignore and ignore the file you actually meant
  2. If you truly want .gitignore untracked, remove it from the index manually: 'git rm --cached .gitignore'
Defensive patterns

Strategy: validation

Validate before calling

// Guard the self-referential case before ignoring:
if node.GetPath() == ".gitignore" {
    return errors.New("refusing to ignore .gitignore itself")
}

Prevention

When it happens

Trigger: Pressing the ignore key ('i' or via the ignore/exclude menu, 'g' menu) while the .gitignore file itself is selected in the files panel.

Common situations: Users selecting .gitignore to inspect it and hitting the ignore key, or muscle-memory 'i' while scrolling an untracked-files list containing .gitignore.

Related errors


AI-assisted analysis of jesseduffield/lazygit@c477a2959b (2026-08-15). Data as JSON: /api/errors/34f1c74e1ff25f1f. Report an issue: GitHub.