You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修复Git Bash中‘fatal: cannot use C:/Users/Administrator/ as an exclude file’错误?

Fixing "fatal: cannot use C:/Users/Administrator/ as an exclude file" in Git Bash

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 06:57:15