.gitignore files added inside Git submodules

I recently reorganized my dotfiles to live inside a Git repository at ~/Dropbox/dotfiles and I'm using pathogen to bundle all Vim addons inside ~/Dropbox/dotfiles/home/.vim/bundle. These addons were added as Git submodules.

Now the problem is, when I run Vim, it automatically generates the documentation for all addons and puts them inside each submodule directory. This adds untracked content to the submodules, which I'd like to avoid.

ruby-1.8.7-p330@gs ~/Dropbox/dotfiles ‹master*› $ git st
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#   (commit or discard the untracked or modified content in submodules)
#
#   modified:   home/.vim/bundle/fuzzyfinder (untracked content)
#   modified:   home/.vim/bundle/l9 (untracked content)
#   modified:   home/.vim/bundle/matchit (untracked content)
#   modified:   home/.vim/bundle/ruby (untracked content)
#   ...
no changes added to commit (use "git add" and/or "git commit -a")

I tried to add a .gitignore file to the root of my Git repository to ignore all doc folders inside submodules, but this doesn't seem to work:

home/.vim/bundle/**/doc

My question: is there a way to ignore files and folders inside Git submodules or maybe configure Vim to create the documentation in a folder outside the Git repository?

EDIT: as Randy Morris pointed out, this might be a duplicate of Generating tags to different location by pathogen


Solution 1:

You should add .gitignore within each of your submodules.
Since said submodules are like nested Git repo, they take care of their own ignore rules, and their status wouldn't be influenced by the .gitignore of the parent repo (as explained here).

For a vim-specific setting, as Randy Morris mentions in the comment, see the SO question "Generating tags to different location by pathogen".


Note: as Nick mentions in this comments, and as illustrated by the answer to "Generating tags to different location by pathogen", a config like:

[submodule "path/to/submodule"]
    path = path/to/submodule
    url = http://github.com/username/repo.git
    ignore = untracked  # <====

will work and make that submodule ignored by git status.
But "ignore = untracked" means at least Git1.7.2.

The config is usually found in the .git/ folder of your repo.


Note: nurettin mentions in the comments:

ignore = dirty did it for me

Commit aee9c7d details the difference between untracked and dirty.

  • "dirty": Only differences of the commit recorded in the superproject and the submodules HEAD will be considered modifications, all changes to the work tree of the submodule will be ignored.
    When using this value, the submodule will not be scanned for work tree changes at all, leading to a performance benefit on large submodules.

  • "untracked": Only untracked files in the submodules work tree are ignored, a changed HEAD and/or modified files in the submodule will mark it as modified.

Solution 2:

VonC's recommendation of ignore = untracked works, but you have to make the change for every such submodule.

If you want to solve the problem once and for all, you can configure a global gitignore pattern on every git repo, by git config --global core.excludesfile ~/.gitignore_global, then just add doc/tags to $HOME/.gitignore_global.

See https://help.github.com/articles/ignoring-files.

Solution 3:

Ben's answer is a good start. But for such specific ignore rule, I don't like the global setting.

Prefer local config for each submodule, and a centralized ignore file in submodule root repository:

cd .vim/bundle
echo "doc/tags" > .gitignore_submodules
git submodule foreach git config --local core.excludesfile "../.gitignore_submodules"