Search code examples
git-submodulesgitignore

Git submodule is ignored


When I try to add a submodule via

git submodule add git@domian:repo.git contact

I get the following message:

The following path is ignored by one of your .gitignore files:

contact

Use -f if you really want to add it.

Here is my .gitignore:

# Ignore everything
*

# But not these files:
!*.py
!*.md
!*.gitignore
!.gitmodules
!contact/

It is resolved by using the suggested -f option, but I am curious why the !contact/ entry in .gitignore does not alleviate the problem.


Solution

  • A submodule is composed of a gitlink (a special entry 160000 in the Git repository index), and a remote URL+path in the .gitmodules.

    So excluding !contact/ would still ignore the gitlink "contact" (which is not a folder contact/, but a special "file")

    This would work better, and allow the git submodule add to proceed:

    !contact
    

    And if any other cause would still block the git submodule add, the next Git 2.26 (Q1 2020) will provide a more helpful error message.