How to globally gitignore the .DS_Store file to avoid tracking it in all Git repositories?
Learn how to globally gitignore the .DS_Store file to prevent it from being tracked in Git repositories. This simple configuration ensures that the macOS system file is ignored across all your Git projects.
To globally ignore the .DS_Store
file in Git, you can use the following steps. The key is to add an entry in the global gitignore file. Here's a snippet to help you achieve this:
-
Open a terminal.
-
Run the following command to open the global gitignore file in your default text editor. If the file doesn't exist, it will create one for you:
git config --global core.excludesfile '~/.gitignore_global'
-
Now, open the global gitignore file with your text editor. For example, using
nano
:nano ~/.gitignore_global
-
Add the following line to the file:
.DS_Store
This line tells Git to globally ignore the
.DS_Store
file. -
Save and close the file. In nano, you can do this by pressing
Ctrl + X
, thenY
to confirm, and finallyEnter
to exit.
Now, Git will ignore the .DS_Store
file globally on your system. Any new Git repository you initialize or clone will automatically apply this global gitignore rule.
Please login or create new account to add your comment.