Do you find yourself adding editor/operating system specific files to every project you work on? Most .gitignore files in projects I've worked on end up as a mess of OS/IDE specific ignore rules.
I see .gitignore files like this all the time.
# OS generated files
.DS_Store
.DS_Store?
.idea
.Spotlight-V100
.Trashes
# Intellij
*.iml
.idea
# VSCode
.vscode/*
*.code-workspace
.history/
# npm
node_modules
You do not need to do this, and in fact probably shouldn't. I'm of the opinion that project specific .gitignore files should only contain things related to the project, such as .env files for development secrets, build artifact folders, anything else you don't want committed that is generated by the project, or specific to the project.
By configuring git's global.excludesFile
, you can create a configuration specific
to your OS/IDE of choice, and never have to add them to a project's
.gitignore again.
git config --global core.excludesFile '~/.gitignore'
All you need to do now is make sure ~/.gitignore
is created with
your own configuration, and you're away.
Here is my minimal global .gitignore file on my personal machine for example:
/**/.DS_Store
.idea
gitignore.io is quite a nice tool for generating OS/IDE specific .gitignore configurations, which you could use to create your own global .gitignore file.