Problem
When a project contains nested git repositories — for example, repositories cloned by Gradle's includegit plugin, git submodules, or any other multi-repository setup — files inside a nested repository (such as checkouts/<name>/build/) appear under the Unversioned Files node in the Commit tool window. They appear even though the parent project's root .gitignore contains a matching rule (for example, **/build/).
Right-clicking such a file in the Project view shows Add to VCS, confirming that the file is not yet tracked by Git.
Cause
Each git repository applies its own ignore rules independently. The .gitignore file in the root of the parent project is not inherited by nested git repositories or submodules — Git treats each repository as a separate scope. As a result, a **/build/ rule placed in the parent project's .gitignore has no effect on files located inside a nested repository.
The Commit tool window groups changes per repository and respects each repository's own .gitignore, the local .git/info/exclude file, and the global gitignore (if configured).
Resolution
- In the Commit tool window, identify the repository header under which the unwanted entries appear. This indicates which nested repository owns the files.
- Open the
.gitignorefile located in the root of that nested repository (not the parent project's.gitignore). - Add the appropriate rule, for example:
build/ - Verify the rule is matched. From a terminal opened in the nested repository:
The output reports whichgit check-ignore -v <path-to-file-or-folder>.gitignoreand which line matched. - The Commit tool window refreshes automatically. To trigger a manual refresh, use Git | Show Git Log > refresh, or restart the IDE.
Apply the same pattern across multiple repositories
To avoid editing every nested repository's .gitignore, configure a global gitignore once:
git config --global core.excludesFile ~/.gitignore_global
Add the desired patterns (for example, build/) to ~/.gitignore_global. The rules apply to all repositories on the machine.
Files already tracked by the nested repository
.gitignore rules do not affect files that are already tracked by Git. If files were committed to the nested repository before the ignore rule was added, untrack them first:
git rm --cached -r <path>
git commit -m "Stop tracking <path>"
After this, the ignore rule takes effect.
Additional information
The IDE setting Settings | Editor | File Types | Ignored Files and Folders (Ctrl+Alt+S on Windows/Linux, ⌘, on macOS) is an IDE-level filter unrelated to Git's .gitignore — it controls which entries the IDE hides in tool windows but does not influence VCS tracking. Use the repository-level .gitignore to control what Git considers untracked.
Comments
0 comments
Please sign in to leave a comment.