There are certain files created by particular editors, IDEs, operating systems, etc., that do not belong in a repository. But adding system-specific files to the repo's .gitignore is considered a poor practice. This file should only exclude files and directories that are a part of the package that should not be versioned (such as the node_modules directory) as well as files that are generated (and regenerated) as artifacts of a build process.
All other files should be in your own global gitignore file:
- Create a file called
.gitignorein your home directory and add any filepath patterns you want to ignore. - Tell git where your global gitignore file is.
The specific name and path you choose aren't important as long as you configure git to find it, as shown below. You could substitute
.config/git/ignorefor.gitignorein your home directory, if you prefer.
git config --global core.excludesfile ~/.gitignore
git config --global core.excludesfile "%USERPROFILE%\.gitignore"
If using Powershell (credit: @kupmanj):
git config --global core.excludesFile "$Env:USERPROFILE\.gitignore"
This will result in an entry in your .gitconfig that looks like this:
[core]
excludesfile = {path-to-home-dir}/.gitignore
Particularly for Windows users, verify any filename was correctly parsed for quotes and expansion: git config --global core.excludesFile
Depending on your system, and whether the XDG_CONFIG_HOME environment variable is set, there might be a default location and
there might actually be a file at that location. The safest thing
Depending on your OS and tools, the following contains sample of what you might want to include. When you run git status before adding any files to your local repo, check to see if any files don't belong. Add them to your global gitignore as appropriate.
# Node
npm-debug.log
# Mac
.DS_Store
# Windows
Thumbs.db
# WebStorm
.idea/
# vi
*~
# General
log/
*.log
# etc...
If you want search to ignore files that you've set in your local .gitignore, you must check:
- Search: Use Ignore Files
If you want search to ignore files that you've set in your global ignore, you must also check this:
- Search: Use Global Ignore Files
Or edit settings directly:
"search.useIgnoreFiles": true,
"search.useGlobalIgnoreFiles": true
you set it to where ever you want it. If you set it with
git config --global core.excludesfile ~/.gitignoreyou have to create it there:~/.gitignore;)