'Windows global gitignore not working... "Untracked files"

Despite having a global gitignore on Windows OS, I am still getting a bunch of "Untracked files".

Below is a truncated list of what it looks like:

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        foo/bar/__pycache__/
        foo/pkg_name.egg-info/
        scripts/MainProcess.log
        scripts/__pycache__/
        test/foo/bar/__pycache__/
        test/test_pkg_name.egg-info/
        venv/

What am I doing wrong? What am I missing?


Background

On Windows 10 Pro my git version is git version 2.34.1.windows.1, and here's my ~/.gitconfig:

[core]
    excludesfile = C:\\Users\\username\\.config\\git\\ignore

git config --list --show-origin outputs:

file:C:/Users/username/.gitconfig       core.excludesfile=C:\Users\username\.config\git\ignore

git check-ignore **.* outputs nothing.

Here is the PowerShell script used to generate the global gitignore:

New-Item -ItemType Directory -Force -Path $Env:USERPROFILE\.config\git

'Global/JetBrains','Global/Vim','Global/VisualStudioCode','Global/macOS','Python','Terraform' `
  | ForEach-Object {
    Invoke-RestMethod -Uri "https://raw.githubusercontent.com/github/gitignore/master/$PSItem.gitignore"
  } > $Env:USERPROFILE\.config\git\ignore

git config --global core.excludesfile $Env:USERPROFILE\.config\git\ignore

The result is a C:\Users\username\.config\git\ignore file in UTF-16 LE encoding with LF endings. You can see the full file in a Pastebin here: https://pastebin.com/a730JHtc

Lastly, the checked out repo also has a per-repo .gitignore (UTF-8 encoding, CRLF line endings) inside that looks like this:

# Follow README.rst instructions on global gitignore

The README.rst instructions it speaks of have been translated into this question.


Research

There are many similar questions like this, none of them solved my problem:

Similar unanswered questions:



Solution 1:[1]

For what it's worth, taking into account the answer, we can update the PowerShell global gitignore creation command to:

New-Item -ItemType Directory -Force -Path $Env:USERPROFILE\.config\git
'Global/JetBrains','Global/Vim','Global/VisualStudioCode','Global/macOS','Python','Terraform' `
  | ForEach-Object {
    Invoke-RestMethod -Uri "https://raw.githubusercontent.com/github/gitignore/master/$PSItem.gitignore"
  } `
  | Add-Content -Encoding UTF8 -Path $Env:USERPROFILE\.config\git\ignore

It turns out the git config --global core.excludesfile $Env:USERPROFILE\.config\git\ignore last line from above is not necessary.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Intrastellar Explorer