I found myself adding .idea
and .DS_STORE
to .gitignore
in every repository I’ve been working on, but then I realized I could take advantage of Git’s global .gitignore
.
To check if there is already a global .gitignore
, run the following command:
git config --get core.excludesfile
If there wasn’t any output, create a file and add the files that you want to ignore globally. I created the file in the ~/.config/.git/
directory:
touch ~/.config/.git/gitignore
echo "/.idea" >> ~/.config/.git/gitignore
echo "/.DS_STORE" >> ~/.config/.git/gitignore
Now, run the following command to set the global .gitignore
:
git config --global core.excludesFile ~/.config/.git/gitignore
NOTE: Project-specific ignore rules should still go into each project’s local .gitignore
to ensure that other contributors have a consistent experience.