lazygit icon indicating copy to clipboard operation
lazygit copied to clipboard

Exclude option ignores core.excludesFile configuration

Open JoeyKL opened this issue 11 months ago • 4 comments

Description

When ignoring files, lazygit currently offers two options:

  1. Add to .gitignore - shared with all developers (tracked)
  2. Add to .git/info/exclude - private, this repository only

However, git supports a third ignore location: core.excludesFile (typically ~/.config/git/ignore), which is for global user patterns that apply to all repositories.

Git's Three Ignore Locations

Per git documentation:

Location Scope Shared? Use Case
.gitignore Project ✅ Yes Build artifacts, dependencies
$GIT_DIR/info/exclude This repo ❌ No User-specific patterns for this repo
core.excludesFile All repos ❌ No Editor files, OS files (e.g., .DS_Store, *.swp)

Feature Request

Add a third option to the ignore menu:

  • Add to global excludes - writes to the user's core.excludesFile

This would be useful for files like:

  • Editor backup files (*.swp, *~, .idea/)
  • OS-generated files (.DS_Store, Thumbs.db)
  • Personal tooling files

Current Menu

Ignore or exclude file
> Add to .gitignore
> Add to .git/info/exclude

Proposed Menu

Ignore or exclude file
> Add to .gitignore              (shared, this repo)
> Add to .git/info/exclude       (private, this repo)  
> Add to global excludes         (private, all repos)

I'm happy to submit a PR implementing this if the approach is acceptable.

JoeyKL avatar Dec 10 '25 16:12 JoeyKL

Makes a lot of sense to me, PR welcome.

stefanhaller avatar Dec 10 '25 16:12 stefanhaller

Ok, after spending quite some time on your PR to get it mergeable, I actually tried it on a real use case, and I have to say that this made me very skeptical of the usefulness of this feature.

The issue is that the command adds the given file's relative path to the global ignore file, which is almost never what you want. It is much more likely that you want to add the selected file's extension as a glob pattern. (We have an existing PR that adds this for the .gitignore file, but apparently it has still problems, and I have never looked at it in much detail.)

The same problem exists for the .gitignore file, but it's much less severe in that case, because the modified .gitignore file will immediately show up in your working tree, so you can press e on it and refine what lazygit added. This is not possible for either .git/info/exclude or core.excludesFile, so I'm thinking it could be more useful to offer a command that simply opens these files in the editor (creating them if needed) instead of automatically adding things to them.

stefanhaller avatar Dec 15 '25 08:12 stefanhaller

That makes sense. I have a particular use case for which adding the file path to core.excludesFile is exactly what I want, but it's unusual (managing dotfiles in my home directory with a different gitignore file name to avoid confusing tools). I can understand why you'd want to go in a different direction since global excludes is the usual use case.

JoeyKL avatar Dec 16 '25 19:12 JoeyKL

Ok; for that unusual use case of yours it seems appropriate to configure a custom command, this shouldn't be hard. Let me know if you need help with that.

As for the feature in general, I would really like to extend it by offering three choices: 1. add the file path, 2. add the file extension, 3. edit the ignore file. The problem is that these choices should be available for all three types of ignore/exclude files, so that makes a total of nine options. Putting them all in one menu is probably too confusing, but having to show two prompts one after the other also doesn't feel right. Not sure how we can solve this in an elegant way, let me know if you have any ideas (or anybody else, of course). BTW, #4390 has the same problem, it offers ignore by extension only for .gitignore but not for the exclude file.

stefanhaller avatar Dec 17 '25 20:12 stefanhaller