What is .DS_Store on Mac?
When you use Git to manage projects, you will probably find .DS_Store files in your repository. What is it and how to remove .DS_Store file from git?
.DS_Store files are system files created by macOS to store metadata related to folder views. While these files are not malicious, they may become problematic if included in your Git repository, especially if you share your project with non-macOS users or if your project is cross-platform.
Following are the steps to remove .DS_Store files from Git repository:
Step 1: Remove Existing .DS_Store from Repository
You can use the following command to delete all existing .DS_Store files in your Git repository:
find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch
This command will search for all .DS_Store files in the repository and remove them from Git.
Step 2: Add .DS_Store into .gitignore File
The next step is to make sure Git ignores .DS_Store files in the future. To do this, add a .DS_Store entry into the .gitignore file. If the .gitignore file doesn’t already exist, you can create one.
echo .DS_Store >> .gitignore
Step 3: Commit Changes
Add the updated .gitignore file to the repository and create a commit to save the changes:
git add .gitignore
git commit -m '.DS_Store deleted!'
By following these steps, you have successfully removed .DS_Store file from your Git repository and configure Git to ignore it in the future. This will help keep your repository clean and consistent across platforms.