Fixed: "bad DVC file name '…' is git-ignored" When You Run dvc add
dvc add stopped with ERROR: bad DVC file name 'data/raw/hour.csv.dvc' is git-ignored. before it tracked anything. The project's .gitignore ignored the whole data folder, and with it the .dvc file DVC wanted to create there. Removing the folder-wide rules, and letting DVC write its own .gitignore files, fixed it.
What I Was Doing
A machine learning project that predicts hourly bike rentals keeps three things it doesn't want in Git: the downloaded dataset, data/raw/hour.csv, the training and test sets it prepares from it, in data/prepared, and the trained model, models/model.skops. Until now, two lines in its .gitignore kept them out:
# Data and models: the pipeline downloads and creates them
/data/
/models/
The next step was to version all three with DVC (Data Version Control). DVC is installed in the project, so it runs through uv run:
uv run dvc add data/raw/hour.csv data/prepared models/model.skops
What I Expected
Three .dvc files, one next to each target, and DVC's usual hint to git add them.
What I Got
ERROR: bad DVC file name 'data/raw/hour.csv.dvc' is git-ignored.

DVC stopped at the first target, with exit code 1, and created nothing.
What I Checked
The message names a .dvc file that didn't exist yet, so I asked Git which rule would ignore each of the three .dvc files:
git check-ignore -v data/raw/hour.csv.dvc data/prepared.dvc models/model.skops.dvc
.gitignore:13:/data/ data/raw/hour.csv.dvc
.gitignore:13:/data/ data/prepared.dvc
.gitignore:14:/models/ models/model.skops.dvc

-v shows the rule behind each answer: the file, the line number and the pattern. Line 13, /data/, ignores everything inside data, so it would ignore data/raw/hour.csv.dvc and data/prepared.dvc too. Line 14, /models/, does the same for models/model.skops.dvc. How to See Why Git Ignores a File with git check-ignore explains the command.
Why It Happens
A .dvc file is the only record of which version of the data belongs to a commit, so it has to be committed. A .dvc file that Git ignores is never committed, never pushed, and never reaches anyone who clones the project.
DVC checks for this before it writes the file. In DVC 3.67.1, dvc/dvcfile.py asks Git whether the path is ignored and raises the FileIsGitIgnored error with this message. The check exists because of DVC issue treeverse/dvc#5650: before it, dvc add accepted such a file, and then, in the issue's words, "attempts to push to a remote is met with a silent failure", and "most alarmingly a dvc pull deletes the data from the workspace". treeverse/dvc#5907 closed that issue, and since then dvc add refuses up front.
The Fix
Remove the folder-wide rules from .gitignore. DVC doesn't need them: dvc add writes a small .gitignore next to each tracked target, which ignores only the data.
# Virtual environments
.venv
-
-# Data and models: the pipeline downloads and creates them
-/data/
-/models/

After the Fix
The same command worked:
uv run dvc add data/raw/hour.csv data/prepared models/model.skops
100% Adding...|███████████████████████████████████████████████████████████|3/3 [00:00, 21.54file/s]
To track the changes with git, run:
git add data/raw/hour.csv.dvc models/.gitignore data/.gitignore data/prepared.dvc data/raw/.gitignore models/model.skops.dvc
To enable auto staging, run:
dvc config core.autostage true
Git now sees the three .dvc files and the .gitignore files DVC wrote, and none of the data:
git status --short --untracked-files=all
M .gitignore
?? data/.gitignore
?? data/prepared.dvc
?? data/raw/.gitignore
?? data/raw/hour.csv.dvc
?? models/.gitignore
?? models/model.skops.dvc

Each of DVC's .gitignore files holds one line, for the one thing tracked in its folder:
| File | Line |
|---|---|
data/raw/.gitignore | /hour.csv |
data/.gitignore | /prepared |
models/.gitignore | /model.skops |
So the data stays out of Git exactly as before, and the .dvc files can be committed.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Ignoring a whole folder that will hold .dvc files | dvc add refuses with is git-ignored | Let dvc add write the ignore rules for the data |
Adding a !*.dvc exception instead | A file inside an ignored folder can't be re-included: the gitignore documentation says "It is not possible to re-include a file if a parent directory of that file is excluded." | Remove the folder rule |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
bad DVC file name '…' is git-ignored | A .gitignore rule matches the .dvc file DVC wants to write | Find it with git check-ignore -v <file>.dvc, then remove or narrow it |
'…' is git-ignored from dvc remove | The same, for a .dvc file that already exists | The same fix |
FAQ
Do I lose anything by removing /data/ from .gitignore?
No. dvc add puts each tracked file or folder into a .gitignore next to it, so Git still ignores the data. Files in data that DVC doesn't track would show up in git status, which is a reminder to track or ignore them.
Does the same happen with dvc.yaml?
The same check runs for dvc.yaml files, which describe pipelines: the error's code is shared by both kinds of DVC file.
Conclusion
ERROR: bad DVC file name 'data/raw/hour.csv.dvc' is git-ignored. meant that a folder-wide rule in .gitignore, /data/, also ignored the .dvc file DVC needed to write. git check-ignore -v found the rule, removing /data/ and /models/ fixed it, and dvc add wrote its own narrower .gitignore files.
Additional Resources
- treeverse/dvc#5650 — why DVC refuses git-ignored
.dvcfiles. - dvc add — how
dvc addupdates.gitignore. - gitignore — Git's pattern rules.
