How to Globally Ignore files like .DS_Store in Git Repos
So, I got tired of adding .DS_Store
to every git repo on my Mac. I was pretty sure there would be a better way to handle this on a global way on my Mac, so I don't have to do this for every repo.
Here's what I found: You can create a global .gitignore
file, add .DS_Store
to it, and have git ignore them in all my repositories at once.
1. Create a Global Git Ignore File
Open up your favorite Terminal app, and type the following -
git config --global core.excludesfile ~/.gitignore_global
This command tells Git where the global `.gitignore` file is located or creates it if it doesn't exist.
2. Edit the Global Git Ignore File
Next, I had to edit this file to include the `.DS_Store` pattern.
Open this global git ignore file in your favorite Text Editor (e.g., nano or vim)
nano ~/.gitignore_global
.DS_Store
By adding this line, I told Git to ignore .DS_Store
files globally.
3. Apply the Changes
Finally, to apply the changesr run the same configuration command again:
git config --global core.excludesfile ~/.gitignore_global
And that's it! No more manually adding .DS_Store
to each individual repository's .gitignore
file. Now, my Mac ignores these files in all Git repositories.