git/list[1] front-page[2] threads[3] people[4] search[5] about
 

git-add ignores exclude markers for ignored files

From
Rrahn <rahn>
Date
Nov 4, 2025, 15:59 UTC
Message-ID
<MN0PR01MB761143093D1A4D226E8883A380C4A@MN0PR01MB7611.prod.exchangelabs.com>
Hey all,
I’ve run into a strange behavior of git-add that I believe is not correct. I couldn’t find something on the mailing list regarding this, so I am writing a new mail. The issue is that if you use git-add with an explicit pathspec with an exclude pattern of a file that is ignored by some .gitignore file (locally or globally) the git-add command errors with the following message:
 
git add --":(exclude)ignored.txt"
The following paths are ignored by one of your ".gitignore" files:
ignored.txt
Note: Use -f if you really want to add them.
Note: Disable this message with "git config set advice.addIgnoredFile false"
Steps to reproduce:
mkdir git-add-test 
cd git-add-test
git init
touch .gitignore
echo “ignored.txt” >>.gitignore
touch ignored.txt
git add --“:(exclude)ignored.txt”
 
Expected behavior:
 
The git add command recognizes that the file ignored.txt is already excluded despite of it being ignored by some gitignore and thus does not check if it is ignored or not. It simply will not be added. 
Note forcing git-add will do the trick, but this could also have side effects for some files that are ignored but not present in the list of excluded files.
Hence, this can’t be the right solution.
Any advice or confirmation are much appreciated.
 
Thank you
René Rahn
Next: Junio C Hamano
Message 1 of 4 in “git-add ignores exclude markers for ignored files”
  1. rahnNov 4, 2025
  2. Junio C HamanoNov 4, 2025
  3. Junio C HamanoNov 5, 2025
  4. Junio C HamanoJan 20, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.