# submodule: allow submodule directory in gitignore

4 messages from 2015-10-12 to 2015-10-19. Participants: Aleksey Komarov, Jiang Xin.
Thread: https://gitlist.dev/t/40535

## Aleksey Komarov, 2015-10-12 06:30

Subject: submodule: allow submodule directory in gitignore
Message-ID: <561B5372.7040508@gmail.com>
URL: https://gitlist.dev/e/561B5372.7040508%40gmail.com

```
Hi all!

I'm sorry if the letter came twice. I have troubles with my post client.

I want to organize my repository so its submodules would be located at the root
of repository. I'm trying to create .gitignore to ignore all files and don't
ignore directories at the same time:

$ cat .gitignore
*
!*/

Now, I'm trying to add a submodule to my repository, but fail to understand why
my .gitignore prevents it from being added. I use the following command to check
if my submodule will be ignored or not:

$ git add --dry-run --ignore-missing c/

I have noticed that result of this check is different when directory c/ already
exists and when it still doesn't by the time of the check.
The described behavior is illustrated by the following example:

$ mkdir git_test
$ cd git_test
$ git init
Initialized empty Git repository in D:/temp/git_test/.git/
$ echo \* >> .gitignore
$ echo \!\*\/ >> .gitignore
$ git add --dry-run --ignore-missing c/
The following paths are ignored by one of your .gitignore files:
c/
Use -f if you really want to add them.
$ mkdir c
$ git add --dry-run --ignore-missing c/
$

Is this behavior expected? If yes, where can I read about it? Which part of the
Git documentation should I consult?
How should I correct my .gitignore to pass this check in both cases, when
directory c/ exists and when it doesn't?

```

## Aleksey Komarov, 2015-10-16 09:33

Subject: Re: submodule: allow submodule directory in gitignore
Message-ID: <5620C46F.8040007@gmail.com>
URL: https://gitlist.dev/e/5620C46F.8040007%40gmail.com
In-Reply-To: <561B5372.7040508@gmail.com>

```
On 12.10.2015 13:30, Aleksey Komarov wrote:

> Now, I'm trying to add a submodule to my repository, but fail to understand why
> my .gitignore prevents it from being added. I use the following command to check
> if my submodule will be ignored or not:
> 
> $ git add --dry-run --ignore-missing c/

By the way I've just consulted documentation[1].
Can --ignore-missing option be used for checking not already present
directories, in addition to ordinary files?

[1] https://git-scm.com/docs/git-add

```

## Jiang Xin, 2015-10-17 12:46

Subject: Re: submodule: allow submodule directory in gitignore
Message-ID: <CANYiYbHNX+j6BPahWdGQ2qVbvBV-wd-Bi=ZjDmRfbXCsboNXpg@mail.gmail.com>
URL: https://gitlist.dev/e/CANYiYbHNX%2Bj6BPahWdGQ2qVbvBV-wd-Bi%3DZjDmRfbXCsboNXpg%40mail.gmail.com
In-Reply-To: <561B5372.7040508@gmail.com>

```
2015-10-12 14:30 GMT+08:00 Aleksey Komarov <leeeeha@gmail.com>:
> Hi all!
>
> I'm sorry if the letter came twice. I have troubles with my post client.
>
> I want to organize my repository so its submodules would be located at the root
> of repository. I'm trying to create .gitignore to ignore all files and don't
> ignore directories at the same time:
>
> $ cat .gitignore
> *
> !*/
>
> Now, I'm trying to add a submodule to my repository, but fail to understand why
> my .gitignore prevents it from being added. I use the following command to check
> if my submodule will be ignored or not:
>
> $ git add --dry-run --ignore-missing c/
>
> I have noticed that result of this check is different when directory c/ already
> exists and when it still doesn't by the time of the check.
> The described behavior is illustrated by the following example:
>
> $ mkdir git_test
> $ cd git_test
> $ git init
> Initialized empty Git repository in D:/temp/git_test/.git/
> $ echo \* >> .gitignore
> $ echo \!\*\/ >> .gitignore
> $ git add --dry-run --ignore-missing c/
> The following paths are ignored by one of your .gitignore files:
> c/
> Use -f if you really want to add them.
> $ mkdir c
> $ git add --dry-run --ignore-missing c/
> $
>

To check how an entry (c/) is affected by .gitignore in different cases,
you can try this command:

    $ git check-ignore -v c/

```

## Aleksey Komarov, 2015-10-19 02:24

Subject: Re: submodule: allow submodule directory in gitignore
Message-ID: <5624545A.5090102@gmail.com>
URL: https://gitlist.dev/e/5624545A.5090102%40gmail.com
In-Reply-To: <CANYiYbHNX+j6BPahWdGQ2qVbvBV-wd-Bi=ZjDmRfbXCsboNXpg@mail.gmail.com>

```


On 17.10.2015 19:46, Jiang Xin wrote:
> 2015-10-12 14:30 GMT+08:00 Aleksey Komarov <leeeeha@gmail.com>:
>> Hi all!
>>
>> I'm sorry if the letter came twice. I have troubles with my post client.
>>
>> I want to organize my repository so its submodules would be located at the root
>> of repository. I'm trying to create .gitignore to ignore all files and don't
>> ignore directories at the same time:
>>
>> $ cat .gitignore
>> *
>> !*/
>>
>> Now, I'm trying to add a submodule to my repository, but fail to understand why
>> my .gitignore prevents it from being added. I use the following command to check
>> if my submodule will be ignored or not:
>>
>> $ git add --dry-run --ignore-missing c/
>>
>> I have noticed that result of this check is different when directory c/ already
>> exists and when it still doesn't by the time of the check.
>> The described behavior is illustrated by the following example:
>>
>> $ mkdir git_test
>> $ cd git_test
>> $ git init
>> Initialized empty Git repository in D:/temp/git_test/.git/
>> $ echo \* >> .gitignore
>> $ echo \!\*\/ >> .gitignore
>> $ git add --dry-run --ignore-missing c/
>> The following paths are ignored by one of your .gitignore files:
>> c/
>> Use -f if you really want to add them.
>> $ mkdir c
>> $ git add --dry-run --ignore-missing c/
>> $
>>
> 
> To check how an entry (c/) is affected by .gitignore in different cases,
> you can try this command:
> 
>     $ git check-ignore -v c/

I try it, but result is the same.

$ rmdir c
$ git check-ignore -v c/
.gitignore:1:* c/
$ mkdir c
$ git check-ignore -v c/
.gitignore:2:!*/ c/

Behavior depends on whether c/ directory exists beforehand.

```
