PricingSign inDownload

Blog / git

Git won't add a file your coding agent created

Your agent wrote a file you need, but git status doesn't show it and git add says it's ignored. Find the rule that hides it and track just that file.

On this page
  1. Confirm it's ignored
  2. Find the rule
  3. Fix it: un-ignore just that file
  4. The folder catch
  5. Or force-add it once
  6. Before you un-ignore anything
  7. Tell the agent
  8. Where Joxo fits
  9. Frequently asked questions
  10. How do I see why git ignores a file?
  11. Why doesn't git status show a new file?
  12. Why doesn't !file work in my .gitignore?
  13. Is git add -f safe?
  14. Where is my global gitignore?
  15. Try it with your team

Your agent wrote a migration, an .env.example, or a fixture under build/. You can see the file on disk, but git status says nothing about it, and the agent's commit went out without it. When you add it yourself, git refuses. The file is ignored, and the rule that ignores it may not even be in your project. We ran every command here with git 2.43 on test repositories.

Confirm it's ignored#

Ignored files don't show up in a plain git status. Ask for them:

bash
git status --short --ignored
!! .env.example
!! debug.log
!! src/

!! marks ignored paths. Note that git shows the folder src/ here, not the file inside it: when everything new in a folder is ignored, it reports the folder.

Adding the file prints the same answer:

bash
git add .env.example
The following paths are ignored by one of your .gitignore files:
.env.example
hint: Use -f if you really want to add them.

An agent that runs git add -A gets no message at all, because ignored files are skipped quietly. That's how a file it created ends up missing from its own commit.

Find the rule#

git check-ignore -v names the file, line and pattern behind each ignored path:

bash
git check-ignore -v .env.example src/build/schema.sql
.gitignore:3:.env*	.env.example
.gitignore:1:build/	src/build/schema.sql

Here .env* was meant for .env and .env.local, and it also catches .env.example. And build/ without a leading slash matches a folder called build anywhere, not only at the top.

Patterns can live in four places, and check-ignore searches all of them:

  • .gitignore files in the project, in any folder.
  • .git/info/exclude, which is local to your clone and never committed.
  • Your global ignore file, ~/.config/git/ignore by default, or whatever core.excludesFile points to.
  • A teammate's or the agent's own global ignore, if it runs as another user.

The last two explain the frustrating case where the file is ignored for you and not for a teammate, or the other way round. For a global rule, the output names the global file:

/home/dev/.config/git/ignore:1:*.sql	notes.sql

When two files match, check-ignore shows the one that wins. A .gitignore in the project beats .git/info/exclude, which beats the global file.

Fix it: un-ignore just that file#

If the file belongs in the repository for everyone, add an exception after the rule that catches it:

.env*
!.env.example

The ! re-includes a path. Check it took:

bash
git check-ignore -v .env.example
git status --short
.gitignore:4:!.env.example	.env.example
?? .env.example

check-ignore still prints a line, this time the negation, and git status now shows the file as untracked, ready to add.

The folder catch#

This one doesn't work:

build/
!src/build/schema.sql

We tried it and the file stayed ignored. Git can't re-include a file if a folder above it is excluded, because it never looks inside that folder. Ignore the folder's contents instead of the folder, then make the exception:

**/build/*
!**/build/schema.sql
bash
git check-ignore -v src/build/out.js src/build/schema.sql
.gitignore:1:**/build/*	src/build/out.js
.gitignore:2:!**/build/schema.sql	src/build/schema.sql

out.js stays ignored and schema.sql is back. If the folder is nested deeper, each excluded folder level needs the same treatment.

Or force-add it once#

If you want this file tracked but don't want to change the rules:

bash
git add -f src/build/schema.sql

Once a file is tracked, ignore rules no longer apply to it: git keeps tracking its changes. That's fine for one file. It also surprises people later, because the .gitignore says the folder is ignored and the file is plainly in the repository. Leave a comment next to the rule if you do this.

Before you un-ignore anything#

Most ignore rules are there for a reason, and the file your agent wants committed may be one you shouldn't. Check what the file is before you track it:

  • Secrets. .env, .env.local, key files and credentials should stay ignored. An .env.example with made-up values is fine; an .env with real keys is not. If one slipped into a commit already, see stop a coding agent committing secrets.
  • Generated output. Build folders, bundles and coverage reports are rebuilt on every machine. Committing them makes noisy diffs and conflicts; see an agent committed node_modules.
  • Large files. A model, a dataset or a database dump can be ignored for size. Look at a large file your agent committed first.

Tell the agent#

Agents add files with git add -A or git add . and assume that covers everything. Two lines in CLAUDE.md or AGENTS.md help:

  • After committing, run git status --short --ignored and say if a file you created is ignored.
  • Never edit .gitignore or use git add -f without asking.

The second one matters because the agent's easiest fix for "file is ignored" is to delete the rule, and that rule may be the one keeping your .env out of the repository.

Where Joxo fits#

The file that's ignored on your machine and not on a teammate's is a classic two-person problem: their agent commits it, yours never sees it. In Joxo, your agents share one project with notes every agent reads before it starts, so a rule like "never edit .gitignore" applies to everyone's agent. Setup is one line pasted into your agent.

Frequently asked questions#

How do I see why git ignores a file?#

Run git check-ignore -v with the path. It prints the ignore file, the line number and the pattern that matched, including rules in .git/info/exclude and your global ignore file.

Why doesn't git status show a new file?#

It's probably ignored. Run git status --short --ignored; ignored paths are marked with !!. Then run git check-ignore -v on the file to find the rule.

Why doesn't !file work in my .gitignore?#

A folder above the file is ignored, and git never looks inside an ignored folder. Ignore the folder's contents with folder/* instead of the folder, then add the !folder/file exception.

Is git add -f safe?#

It tracks that one file despite the rules, and later changes to it are tracked too. Check the file isn't a secret or generated output first, and leave a note by the rule so nobody is surprised.

Where is my global gitignore?#

By default it's ~/.config/git/ignore. If core.excludesFile is set, git uses that file instead; git config --show-origin core.excludesFile shows where it's set.