# gitignore documentation for info/exclude files and patterns with relative directories

3 messages from 2026-03-27 to 2026-03-28. Participants: Dan Drake, Junio C Hamano, Shreyansh Paliwal.
Thread: https://gitlist.dev/t/65368

## Dan Drake, 2026-03-27 11:20

Subject: gitignore documentation for info/exclude files and patterns with relative directories
Message-ID: <Qdk5yVH_yWgKl_bjCjdasusfe3PuzHCZ2rKgKIn2Xx5rcw46jmQDfA6K2vkv3V3XLSy4aqwyUlfVEmF5VlIv3EVEOlZLEnf-paw11tyhZKE=@dandrake.org>
URL: https://gitlist.dev/e/Qdk5yVH_yWgKl_bjCjdasusfe3PuzHCZ2rKgKIn2Xx5rcw46jmQDfA6K2vkv3V3XLSy4aqwyUlfVEmF5VlIv3EVEOlZLEnf-paw11tyhZKE%3D%40dandrake.org

```
Hello,

In the "pattern format" section of the gitignore manpage, it says:

> The slash "/" is used as the directory separator. Separators may occur at the
> beginning, middle or end of the .gitignore search pattern.
>
> If there is a separator at the beginning or middle (or both) of the pattern,
> then the pattern is relative to the directory level of the particular
> .gitignore file itself. Otherwise the pattern may also match at any
> level below the .gitignore level.

For a .git/info/exclude file, the above makes it sound like the pattern will be 
relative to that .git/info directory, so that you would need to use this kind of p
attern to match files starting with 'foo' in the root of the repo:

../../foo*

However, it seems that for patterns in the info/exclude file, the beginning
slash anchors the pattern to the root of the repo; the above pattern
in that file should be '/foo*'.

The documentation should mention this behavior for info/exclude, as well as 
the core.excludesFile.



Dan





--
Ceci n'est pas une .signature.


```

## Junio C Hamano, 2026-03-27 16:18

Subject: Re: gitignore documentation for info/exclude files and patterns with relative directories
Message-ID: <xmqqwlyxkzyy.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqwlyxkzyy.fsf%40gitster.g
In-Reply-To: <Qdk5yVH_yWgKl_bjCjdasusfe3PuzHCZ2rKgKIn2Xx5rcw46jmQDfA6K2vkv3V3XLSy4aqwyUlfVEmF5VlIv3EVEOlZLEnf-paw11tyhZKE=@dandrake.org>

```
Dan Drake <dan@dandrake.org> writes:

> The documentation should mention this behavior for info/exclude, as well as 
> the core.excludesFile.

Yup, my mistake more than 20-year-old that nobody complained so far
;-)

Yes, these exclude pattern sources that are outside the working tree
behave as if they are specified at the root level of the working
tree.

Patches welcome. Thanks.

```

## Shreyansh Paliwal, 2026-03-28 15:21

Subject: [PATCH] doc: gitignore: clarify pattern base for info/exclude and core.excludesFile
Message-ID: <20260328152233.1140327-1-shreyanshpaliwalcmsmn@gmail.com>
URL: https://gitlist.dev/e/20260328152233.1140327-1-shreyanshpaliwalcmsmn%40gmail.com
In-Reply-To: <xmqqwlyxkzyy.fsf@gitster.g>

```
The pattern format section describes how patterns are interpreted
relative to the location of a .gitignore file, but does not mention
the behavior for exclude sources outside the working tree.

Clarify that patterns from $GIT_DIR/info/exclude and core.excludesFile
are treated as if they are specified at the root of the working tree,
so a leading '/' anchors matches at the repository root.

Reported-by: Dan Drake <dan@dandrake.org>
Signed-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
---
 Documentation/gitignore.adoc | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/Documentation/gitignore.adoc b/Documentation/gitignore.adoc
index 9fccab4ae8..a3d24e5c34 100644
--- a/Documentation/gitignore.adoc
+++ b/Documentation/gitignore.adoc
@@ -96,6 +96,11 @@ PATTERN FORMAT
    particular `.gitignore` file itself. Otherwise the pattern may also
    match at any level below the `.gitignore` level.
 
+ - Patterns read from exclude sources that are outside the working tree,
+   such as $GIT_DIR/info/exclude and core.excludesFile, are treated as if
+   they are specified at the root of the working tree, i.e. a leading "/"
+   in such patterns anchors the match at the root of the repository.
+
  - If there is a separator at the end of the pattern then the pattern
    will only match directories, otherwise the pattern can match both
    files and directories.
-- 
2.53.0

```
