Create a Global .gitignore
.gitignore file is cherished by developers because it can keep repositories clean after build files and OS-generated files (like
.DS_Store) clutter the structure of your repository. What I find is that I'm constantly adding the same files and directories (like
node_modules) to every repository and I find it tedious. I was hoping there was a way to globally ignore those files and directories ... and I've found it.
You can create your global
.gitignore with this magic:
# Declare the global .gitignore git config --global core.excludesfile ~/.gitignore_global # Create the .gitignore_global file touch .gitignore_global # Go into edit mode so you can add the unwanted file listing vim .gitignore_global
The snippet above creates a
.gitignore_global in your user directory which is respected throughout your user directory. Now you don't have to explicitly, repeatedly add the same files and directories to individual
.gitignore files! Excellent!
This shouldn't be considered a great solution for collaborative repositories though -- someone else will inadvertently submit unwanted files and directories because the repo's own
.gitignore doesn't contain the unwanted file listing. For your own purposes, however, a global
.gitignore is aces!