honey_badger
honey_badger

Reputation: 530

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.

Upvotes: 0

Views: 1703

Answers (2)

VonC
VonC

Reputation: 1324278

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.

Upvotes: 2

wfsch
wfsch

Reputation: 31

I don't hit that error in your particular case (I have git version 2.21.0.windows.1).

I do hit that error when trying to add a submodule outside the parent repository, though (which apparently isn't supported):

$ git submodule add https://github.com/user/repo ../repo
The following path is ignored by one of your .gitignore files:
../repo
Use -f if you really want to add it.

Best guess is it's a bug...so adding !contact/ to your .gitignore doesn't fix it because it's not actually the .gitignore causing the problem.

What git version do you have? You can download the source code for your particular version, search for the error message (e.g. here it is in v2.21), and trace through the code to figure out what actually goes wrong.

Upvotes: 0

Related Questions