如何修复Git Bash中‘fatal: cannot use C:/Users/Administrator/ as an exclude file’错误?
Hey there, let's get this Git error sorted out quickly! This issue pops up because Git's core.excludesFile configuration is pointing to a directory (your user folder C:/Users/Administrator/) instead of a specific exclude file like .gitignore_global or .gitexclude. Here's how to fix it step by step:
Step 1: Confirm the problematic configuration
First, check what your current global core.excludesFile setting is by running this command in Git Bash:
git config --global core.excludesFile
If the output is C:/Users/Administrator/ (a directory), that's definitely the root cause.
Step 2: Create a global ignore file (if you don't have one)
Git expects core.excludesFile to point to a valid file. Let's create a global .gitignore_global file in your user directory:
touch ~/.gitignore_global
The ~ shortcut here refers to your C:/Users/Administrator/ folder, so this creates the file directly there.
Step 3: Update the Git configuration
Now set core.excludesFile to point to the file you just created:
git config --global core.excludesFile ~/.gitignore_global
Step 4: Verify the fix
Double-check the configuration to make sure it's correct:
git config --global core.excludesFile
You should see the full path to your .gitignore_global file (e.g., C:/Users/Administrator/.gitignore_global) instead of the directory.
Bonus: Check local repository configuration (if needed)
If the error still persists, it might be that a local repository has its own incorrect core.excludesFile setting. Navigate to your repo folder and run:
git config core.excludesFile
If it returns a directory path, unset the local config with:
git config --unset core.excludesFile
Or set it to a valid local exclude file if you need one.
After completing these steps, try running git add . again—it should work without the error!
内容的提问来源于stack exchange,提问作者Rida Farhan

