Skip to content

symlinked gitignore file fails with "fatal: cannot use <path> as an exclude file" #1392

@0xabu

Description

@0xabu
  • I was not able to find an open or closed issue matching what I'm seeing

Setup

  • Which version of Git for Windows are you using? Is it 32-bit or 64-bit?
$ git --version --build-options
git version 2.15.1.windows.2
built from commit: 5d5baf91824ec7750b103c8b7c4827ffac202feb
sizeof-long: 4
machine: x86_64
  • Which version of Windows are you running? Vista, 7, 8, 10? Is it 32-bit or 64-bit?
$ cmd.exe /c ver
Microsoft Windows [Version 10.0.16299.98]
  • What options did you set as part of the installation? Or did you choose the
    defaults?
> type "c:\Program Files\Git\etc\install-options.txt"
Editor Option: VIM
Path Option: Cmd
SSH Option: OpenSSH
CURL Option: OpenSSL
CRLF Option: CRLFAlways
Bash Terminal Option: MinTTY
Performance Tweaks FSCache: Enabled
Use Credential Manager: Enabled
Enable Symlinks: Disabled

However, I have also tried manually changing the symlink setting:

> type c:\ProgramData\Git\config
[core]
        symlinks = true
        autocrlf = true
        fscache = true
(...)
> git config --global --get core.symlinks
true

Details

  • Which terminal/shell are you running Git from? e.g Bash/CMD/PowerShell/other

This repros from both CMD and Cygwin ZSH

I try to keep all my configuration files in OneDrive, and use symlinks to point to them. I have both ~/.gitconfig and ~/.gitignore in OneDrive. Cygwin and WSL git are both happy with this arrangement, but Git for Windows ignores and refuses to use a symlinked .gitignore file (even if it's still happy with a symlink at ~/.gitconfig).

Here's a self-contained repro, starting from C:\Users\<me>:

> echo "somepattern" > .gitignore
> git config --global core.excludesfile ~/.gitignore
> type .gitconfig
[core]
        excludesfile = ~/.gitignore
> mkdir tmp
> cd tmp
> git init
Initialized empty Git repository in c:/Users/<me>/tmp/.git/
> git status
On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track)
> cd ..
> mv .gitignore thegitignore
> mklink .gitignore thegitignore
symbolic link created for .gitignore <<===>> thegitignore
> cd tmp
> git status
fatal: cannot use C:/Users/<me>/.gitignore as an exclude file
  • What did you expect to occur after running these commands?

Git reads and uses my custom .gitignore file, just as it did in the first instance of "git status" when it wasn't a symlink.

  • What actually happened instead?

Git prints the warning:

fatal: cannot use C:/Users/<me>/.gitignore as an exclude file

and ignores the contents of that file.

A syscall trace shows that git is actually following the symlink and reading the contents of the linked file before ignoring it, so it's unclear what exactly is wrong with having a symlink there:

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions