Blog / git
Your coding agent cloned a repo inside yours
An agent cloned a library into your project and committed it as an empty folder. Untrack it, then ignore it, vendor the files, or make it a real submodule.
On this page
- What git warned about
- Check whether it happened
- Step one, whatever you choose: untrack it
- Option 1: it was only for reading, so ignore it
- Option 2: you want the files in your repository
- Option 3: you want a real submodule
- If the commit is already pushed
- If the agent also changed the inner repository
- Stop it happening again
- Where Joxo fits
- Frequently asked questions
- What does "adding embedded git repository" mean?
- How do I remove an embedded git repository from my commit?
- Why is the folder empty when my teammate clones?
- Does git rm --cached delete the folder?
- Do I need to rewrite history to fix it?
- Try it with your team
You asked your agent to look at how a library does something, and it ran git clone inside your project to read the source. Later it ran git add . and committed. Now your teammate pulls and finds an empty folder where the library should be, and git submodule status fails. Git didn't commit the library's files. It committed a pointer to one commit of it, with nothing to say where that commit lives. Here's how to spot it and the three ways out. We ran every command with git 2.43 on test repositories.
What git warned about#
When the agent ran git add ., git printed a long warning. Agents tend to skip past it:
warning: adding embedded git repository: vendor-lib
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint:
hint: git submodule add <url> vendor-lib
hint:
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint:
hint: git rm --cached vendor-libThe warning is only a warning, so the add and the commit both went through.
Check whether it happened#
A folder that holds its own .git gets stored as a single entry of type 160000, called a gitlink. List them:
git ls-files -s | grep '^160000'160000 93687248fdc84db872f3c245673421a10254b27f 0 vendor-libThe hash is the commit the inner repository was on. A real submodule also has an entry in a .gitmodules file that says where to fetch it from. An accidental one has none, which is why this fails:
git submodule statusfatal: no submodule mapping found in .gitmodules for path 'vendor-lib'Anyone who clones your repository gets vendor-lib as an empty folder. On your machine it looks fine, because the agent's clone is still sitting there. That's why it often goes unnoticed until someone else pulls.
To find every nested repository in the working copy, tracked or not:
find . -mindepth 2 -name .git -not -path './node_modules/*'Step one, whatever you choose: untrack it#
Remove the gitlink from the index. --cached leaves the folder and its files on your disk:
git rm --cached vendor-lib
git status --shortD vendor-lib
?? vendor-lib/Git now plans to delete the pointer and sees the folder as untracked. Nothing on disk has changed. Now decide what the folder should be.
Option 1: it was only for reading, so ignore it#
Most of the time the agent cloned the library to read it, and your project doesn't need it at all. Ignore it and commit:
echo 'vendor-lib/' >> .gitignore
git add .gitignore
git commit -m "Stop tracking vendor-lib"Then delete the folder when the agent is done with it. Better still, have agents clone reference repositories outside your project, for example under /tmp or a folder of their own, so they never land in git add ..
Option 2: you want the files in your repository#
If your project should carry a copy of the code, remove the inner .git folder so it becomes ordinary files, then add them:
rm -rf vendor-lib/.git
git add vendor-lib
git status --shortD vendor-lib
A vendor-lib/a.jsThe pointer goes and the real files come in. Check the library's licence before you commit someone else's code into yours, and note the version you copied in the commit message, since the history that came with it is gone.
Option 3: you want a real submodule#
If the library should stay a separate repository that your project pins to one version, register it properly. With the folder already cloned, git submodule add reuses it:
git submodule add https://github.com/example/lib.git vendor-lib
git status --shortAdding existing repo at 'vendor-lib' to the index
A .gitmodules.gitmodules now records the path and URL, so a teammate can run git submodule update --init and get the files. Use the URL people can actually reach, not a path on the agent's machine. Submodules have their own workflow to learn, so only pick this if your team wants it; a package manager is usually simpler.
If the commit is already pushed#
The steps are the same. Untrack, pick an option, and commit the fix on top. You don't need to rewrite history: the old commit holds only a pointer, not the library's files, so there's nothing large or private to scrub out of it.
That's different from an agent committing a real copy of a big folder. If the agent added node_ or a large build output, the files really are in history; see remove a large file your agent committed.
If the agent also changed the inner repository#
Sometimes the agent edits files inside the clone and then commits there too. Your outer repository only records which commit the inner one is on, so those edits exist nowhere but that folder. Before you delete it, check:
git -C vendor-lib status --short
git -C vendor-lib log --oneline -5If there's work worth keeping, copy it into your own project or save it as a patch with git -C vendor-lib format-patch -1.
Stop it happening again#
- Say where to clone. Add a line to CLAUDE.md or AGENTS.md: clone reference repositories outside the project folder, never inside it.
- Don't let agents run git add . Ask them to add the files they changed by name. That keeps out clones, logs and other leftovers.
- Catch it before the commit. A pre-commit hook can refuse gitlinks that have no
.gitmodulesentry: ifgit diff --cached --diff-filter=A --name-onlylists a path thatgit ls-files -sshows with mode160000, stop the commit. Then make sure the agent doesn't skip your hooks. - Look at the diff. A gitlink shows in
git diff --cachedasSubproject commitfollowed by a hash. One line like that in a review is the sign.
Where Joxo fits#
When your agent and a teammate's agent work on one project, a commit like this breaks the other person's checkout, not yours. In Joxo, you see each agent's commits as they land and who made them, so an empty folder gets noticed before it reaches anyone else. Setup is one line pasted into your agent.
Frequently asked questions#
What does "adding embedded git repository" mean?#
You ran git add on a folder that has its own .git inside. Git stored a pointer to that repository's current commit instead of its files, so anyone who clones yours gets an empty folder.
How do I remove an embedded git repository from my commit?#
Run git rm --cached <folder> to untrack it, then either ignore the folder, delete its .git and add the files, or add it as a real submodule. Commit the result.
Why is the folder empty when my teammate clones?#
Git committed only a gitlink, a pointer to one commit, with no .gitmodules entry saying where to fetch it. Clones have no way to get the files.
Does git rm --cached delete the folder?#
No. It removes the entry from the index only. The folder and its files stay on your disk.
Do I need to rewrite history to fix it?#
No. The old commit contains only the pointer, not the library's files. Commit the fix on top.