.gitignore files added inside Git submodules

GitVimGitignoreGit Submodules

Git Problem Overview


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 https://stackoverflow.com/questions/4343544/generating-tags-to-different-location-by-pathogen#4346300

Git Solutions


Solution 1 - Git

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 - Git

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 - Git

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"

Solution 4 - Git

I think the basic problem here is that you are trying to ignore a 'tracked' change. .gitignore ignores only 'untracked' changes to the repo. To verify you can modify some file in your repo (which tracked) and also add it to your .gitignore file. On doing git status you will see that the file is still listed as 'modified'. Your submodule repo's are also considered tracked by your main repo, hence simply adding a gitignore to the parent repo won't work. As othere suggested, either add .gitignore rules individual repo's or if you're using a recent git version, you can use the git status --ignore-submodules.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionrubiiiView Question on Stackoverflow
Solution 1 - GitVonCView Answer on Stackoverflow
Solution 2 - GitBen ChallenorView Answer on Stackoverflow
Solution 3 - GitJérômeView Answer on Stackoverflow
Solution 4 - GitMandeep SandhuView Answer on Stackoverflow