Darren
Darren

Reputation: 11011

How to use global gitignore with Visual Studio Code?

I have a global gitignore file defined in my gitconfig but Visual Studio Code seems to not be interpreting it. How would I use a global gitignore with Visual Studio Code?

Upvotes: 23

Views: 17160

Answers (6)

VonC
VonC

Reputation: 1326776

VSCode 1.75 (Jan 2023) will add documentation to the search.useGlobalIgnoreFiles setting, through PR 169688 (for issue 168129)

Ripgrep (used by VSCode) seems to just use the global gitignore as the global ignore.

That setting now says:

useGlobalIgnoreFiles: Controls whether to use your global gitignore file (e.g., from $HOME/.config/git/ignore) when searching for files.
Requires search.useIgnoreFiles to be enabled.

This is available in VSCode Insiders today.


As noted by Yann Duran in the comments, even when search.useGlobalIgnoreFiles is set to true, the git config --get core.excludesFile, if it has been set, will be used by VSCode.

Upvotes: 0

Max
Max

Reputation: 566

This steps to Windows:

  1. Open GitBash Terminal
  2. Run touch ~/.gitignore_global to create a global .gitignore file in the home directory
  3. Edit file in your home directory: ~/.gitignore_global
  4. Add .vscode/ and any other files or directories that you want to ignore and not include in project-specific .gitignore files;
  5. Save file;
  6. In GitBash run git config --global core.excludesfile ~/.gitignore_global

Done! That’s it! Using .gitignore_global will let you customize your editor without having to edit and commit changes to the .gitignore file for every single project.

Upvotes: 9

Ulysse BN
Ulysse BN

Reputation: 11403

EDIT: Comment from Piyush Soni.

As of 9 august 2021, for this configuration to work, you also have to check useIgnoreFiles, hence:

"search.useGlobalIgnoreFiles": true,
"search.useIgnoreFiles": true

You have to add these in your settings to allow global gitignore:

"search.useGlobalIgnoreFiles": true

Found on Microsoft/vscode#59364.

For this to work, I also had to restart my VSCode session.


Note that you must already have a global ignore file if you want it to be useful. You can set or see which one is set with the next commands:

# get
git config --global core.excludesFile
# set
git config --global core.excludesFile <filename>

See more details about gitignore on the git documentation.

Upvotes: 30

user12560246
user12560246

Reputation:

I know this thread is several months old but the correct answer for this, today, is to open settings in Code and search for "git" and then check the box "Use Global Ignore Files".

Of course, you can add it manually too, but no need for that now as it has been added in settings.

Upvotes: 4

Ronny Schellenberg
Ronny Schellenberg

Reputation: 1

To ignore vscode globally you can use this in .gitignore file:

**/.vscode

This ignores vscode in all subdirectorys

Upvotes: -7

Darren
Darren

Reputation: 11011

This was an issue on my end, I had to full reference my ignore file in my config for Windows.

Upvotes: -2

Related Questions