How to globally gitignore the .DS_Store file to avoid tracking it in all Git repositories?

Harpreet · · 3245 Views

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:

  1. Open a terminal.

  2. 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'
    
  3. Now, open the global gitignore file with your text editor. For example, using nano:

    nano ~/.gitignore_global
    
  4. Add the following line to the file:

    .DS_Store
    

    This line tells Git to globally ignore the .DS_Store file.

  5. Save and close the file. In nano, you can do this by pressing Ctrl + X, then Y to confirm, and finally Enter 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.

0

Please login or create new account to add your comment.

0 comments