Allow .geminiignore to un-ignore items from .gitignore
What would you like to be added?
I would love it if I could use .geminiignore to override the rules in .gitignore with negative patterns.
As far as I can tell, the current implementation will filter out a file if it appears in either's rules, but there's no support for something like:
# .gitignore
/foo
/bar
/baz
# .geminiignore
!/bar/quux
(I'd love to be corrected, I may have been holding something wrong)
Why is this needed?
Some projects like Fuchsia build a source checkout out of multiple git repositories using tools that wrap git commands. In those projects, a particular subdirectory of the workspace might be in .gitignore but logically still under source control and relevant for a developer (or agent) to read and edit directly.
It would be great to get gcli to read GEMINI.md files in those nested subrepositories when working in the root directory of the workspace so that memory content can be colocated and evolved in lockstep with the source it references.
This feature would also allow for a pattern where a user could have user-and-project-specific memory files under a .gitignored path, analogous to common patterns for user-specific Bazel configuration.
Additional context
ripgrep is one notable precedent for a popular CLI tool that offers a similar hierarchical override approach to ignore files.
I tried implementing this, but it seems that there are some subtle interactions between the file discovery service and some of Gemini's tools and I wasn't sure how to proceed. I'd be interested in giving it another shot if there's interest from maintainers.
Someone else should pick this up -- I don't have time for this at the moment.
Here's a super simple way to setup a repro for this:
#!/bin/bash
# This script sets up a temporary environment to reproduce the .gitignore precedence bug.
set -e
# 1. Create a temporary directory
TEMP_DIR=$(mktemp -d)
echo "✅ Created temporary directory at: $TEMP_DIR"
# 2. Set up a fake .git directory to simulate a git repository
mkdir "$TEMP_DIR/.git"
echo "✅ Created a fake .git directory"
# 3. Set up the .gitignore file to ignore the 'vendor' directory
echo "/vendor/" > "$TEMP_DIR/.gitignore"
echo "✅ Created .gitignore to ignore '/vendor/'"
# 4. Set up the .geminiignore file to negate the gitignore rule
echo "!/vendor/" > "$TEMP_DIR/.geminiignore"
echo "✅ Created .geminiignore to un-ignore '!/vendor/'"
# 5. Create the nested vendor directory and sample files
mkdir -p "$TEMP_DIR/vendor/nested"
echo "console.log('This is vendor/file1.js');" > "$TEMP_DIR/vendor/file1.js"
echo "console.log('This is vendor/nested/file2.js');" > "$TEMP_DIR/vendor/nested/file2.js"
echo "✅ Created sample files in 'vendor/' and 'vendor/nested/'"
# 6. Print instructions for the user
cat << EOF
---
Bug Reproduction Steps:
1. Navigate to the temporary directory in your terminal:
cd "$TEMP_DIR"
2. Run the following command in a new instance of the Gemini CLI:
gemini read all javascript files in the vendor directory
Expected Results:
- **If the bug exists (Current Behavior):** The tool will report that no files were found, because the .gitignore rule is incorrectly taking precedence.
- **If the bug is fixed (Correct Behavior):** The tool will find and display the content of both 'vendor/file1.js' and 'vendor/nested/file2.js'.
---
EOF
Why the f*#*( does gemini disable access to files in the .gitignore in the first place? That's such a weird assumption. Not everything in a .gitignore is a secret. Why are we conflating system configs?
Why the f*#*( does gemini disable access to files in the
.gitignorein the first place? That's such a weird assumption. Not everything in a.gitignoreis a secret. Why are we conflating system configs?
@oojacoboo Correct, not all files in .gitignore are secret files, but often it does contain secret files. Would you rather have your API tokens or secret keys be spread by AI/Gemini, or manually add some more files/folders? I think I would prefer to keep my secrets actually secret and not have an AI read and remember it :)
@jvherck so add a setup step for security. But most people are going to toggle this settting and not further configure their .geminiignore to explicitly ignore secret files. It’s not going to accomplish what they think, aside from maybe give them an “out”.
@oojacoboo The main things .gitignore is used for are generated files and secret files. Neither of those be consumed by the AI... And that's why it's useful to have a custom gemini ignore file. Can ignore even more that git shouldn't ignore, or un-ignore files/folders that git does ignore. It's very logical and useful this way.
@jvherck hard disagree. The only thing it's useful for is secrets - that's it. Generated files are critical to a functioning application. And if you want to debug anything, without wandering around aimlessly, you need to be able to read generated files, including vendor packages.
@oojacoboo For libraries/packages or generated files there is usually documentation (or error codes if you're debugging). If you pass all of your files to the AI, it will consume a lot of input tokens and the price will drive up a lot. I do agree it's necessary to include the generated files or libraries sometimes, but that's why it's useful to un-ignore them in the .geminiignore file. From experience I have noticed many people who use Gemini or other AI's are not that advanced to be using certain / commands in the AI's (terminal) session. For most general usecases it's easier to follow .gitignore restrictions and make some exceptions in the custom .geminiignore file.
@jvherck you know what else drives up token usage? Wandering around aimlessly, trying things out because you have blinders on and only able to read 75% of the code necessary to sufficiently debug the issue.
@oojacoboo You make a good point again there, but still, if not ignoring .gitignore by default and you forget to make the necessary setup, you might leak your secrets/credentials/tokens/... and that might end up costing you a lot more if those get leaked. So I do agree with you not literally everything in .gitignore should be ignored by the AI, but I do think it's good practice to ignore all of it and un-ignore whatever's necessary in a .geminiignore file. And with that I'll stop commenting so neither of us has to continue wasting time about this 😅