This warning occurs when you try to add a file that matches a pattern in your .gitignore. You can force-add the file with `git add -f`, add an exception to .gitignore, or remove the ignore rule entirely.
When you run `git add` on a file, Git checks whether that file matches any patterns in your `.gitignore` files. If a match is found, Git refuses to add the file and displays this warning. This is a protective mechanism to prevent accidentally committing files you explicitly told Git to ignore. Git checks multiple sources for ignore patterns in this order: 1. **Local `.gitignore` files** - Can exist in any directory, affecting that directory and its subdirectories 2. **Repository exclude file** - Located at `.git/info/exclude`, only affects your local clone 3. **Global gitignore** - Configured via `core.excludesFile`, applies to all your repositories The warning message tells you the file is being ignored, but the "Use -f if you really want to add them" hint shows Git will let you override this behavior if you know what you're doing.
Use git check-ignore with the verbose flag to find exactly which pattern is causing the file to be ignored:
git check-ignore -v path/to/your/fileThis outputs the source file, line number, pattern, and pathname. For example:
.gitignore:3:*.log debug.logThis tells you line 3 of .gitignore has the pattern *.log that's matching debug.log.
If you need to track a specific file despite the ignore rule, use the -f or --force flag:
git add -f path/to/your/fileThis overrides the ignore pattern for this specific file. Once the file is tracked, Git will continue tracking it even though the ignore pattern still exists.
Note: This is useful for one-off exceptions but doesn't solve the underlying pattern conflict.
For a permanent solution, add a negation pattern to your .gitignore. Negation patterns start with ! and override previous ignore rules:
# In .gitignore
*.log
!important.logFor files in subdirectories, you may need to also un-ignore parent directories:
# Wrong - won't work if parent is ignored
build/
!build/important-file.txt
# Correct - un-ignore the directory first
build/*
!build/important-file.txtYour global gitignore might be ignoring the file. Check if you have one configured:
git config --global core.excludesFileIf this returns a path (commonly ~/.gitignore or ~/.config/git/ignore), inspect that file:
cat $(git config --global core.excludesFile)Remove or modify any patterns that shouldn't apply to this repository.
Every Git repository has a local exclude file that isn't shared with others:
cat .git/info/excludeThis file uses the same format as .gitignore but only affects your local clone. Remove any patterns here that are blocking files you need to track.
If you're using git add *, the shell expands * to include all files, including ignored ones, which Git then warns about.
Instead, use:
git add .The . tells Git to add all files relative to the current directory, and Git will automatically skip ignored files without warning. This is the recommended way to stage all changes.
If the file type should never have been ignored, remove or modify the pattern in .gitignore:
# Find all .gitignore files in the repository
find . -name ".gitignore" -type f
# Edit the relevant .gitignore
nano .gitignoreAfter modifying .gitignore, stage both the gitignore and the previously-ignored file:
git add .gitignore path/to/your/file### Understanding .gitignore Precedence
Git processes ignore rules in a specific order. Later rules can override earlier ones:
1. Command-line patterns (via --exclude)
2. Patterns from .gitignore in the same directory
3. Patterns from .gitignore in parent directories (up to repository root)
4. Patterns from .git/info/exclude
5. Patterns from the file specified by core.excludesFile
Within each file, patterns are processed top to bottom, with later patterns overriding earlier ones.
### The check-ignore Command
git check-ignore is invaluable for debugging. Additional useful flags:
# Check multiple files at once
git check-ignore -v file1 file2 file3
# Show non-matching files too (requires -v)
git check-ignore -v -n file1 file2
# Check stdin for batch processing
find . -name "*.log" | git check-ignore --stdin -v### Patterns Already Tracked
If a file is already tracked by Git, adding it to .gitignore won't remove it. To stop tracking a file:
# Stop tracking but keep the local file
git rm --cached path/to/file
# Then add the pattern to .gitignore
echo "path/to/file" >> .gitignore
git commit -m "Stop tracking path/to/file"### Global Gitignore Best Practices
Keep your global gitignore for editor/OS-specific files that every repository should ignore:
# Set up global gitignore
git config --global core.excludesFile ~/.gitignore_global
# Common patterns for global gitignore
echo ".DS_Store" >> ~/.gitignore_global
echo "Thumbs.db" >> ~/.gitignore_global
echo "*.swp" >> ~/.gitignore_global
echo ".idea/" >> ~/.gitignore_global
echo ".vscode/" >> ~/.gitignore_global### Disabling the Warning
You can suppress this warning with:
git config advice.addIgnoredFile falseHowever, this hides the warning rather than fixing the issue and is generally not recommended.
warning: BOM detected in file, this may cause issues
UTF-8 Byte Order Mark (BOM) detected in file
fatal: Server does not support --shallow-exclude
Server does not support --shallow-exclude
warning: filtering out blobs larger than limit
Git partial clone filtering large blobs warning
fatal: Server does not support --shallow-since
Server does not support --shallow-since in Git
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server