Snippets - Git

Remove .DS_Store from Git Repository

|
Anuz Pandey

The given code snippet is a set of commands used in Git to ignore and remove unwanted Mac-specific .DS_Store files from a repository. These files are automatically created by macOS Finder to store metadata about folders, such as icon positions and window settings. While these files are harmless on a local system, they can cause problems when accidentally added to a Git repository, as they clutter the commit history and cause unnecessary conflicts for users on different operating systems.

Add below code to you .gitignore file.

Now run these commands.


Let's break down each command and its purpose:

This command removes all files and directories from the Git index (staging area) that match the .DS_Store pattern. The --cached option ensures that the files are only removed from Git's tracking but remain in your local working directory.

After removing the .DS_Store files from the Git index, this command stages all the changes in the working directory to be committed.

This command creates a new commit with the message 🔨 fix: removes git ignored files to permanently record the removal of the .DS_Store files from the repository.

The -f (force) option is used to forcefully push the commit to the remote repository. This is necessary because we've modified the commit history by removing the .DS_Store files.


By executing these commands, you ensure that .DS_Store files are not included in the Git repository going forward, which keeps the repository cleaner and reduces potential conflicts for collaborators using different operating systems. Remember that .DS_Store files should be added to the .gitignore file to prevent them from being inadvertently re-added in the future.

Keep coding, keep exploring, and keep inspiring. 🐼


  • Tags:
  • DS_Store
  • mac
  • github
  • git