When developing code, it’s common to have files and directories that shouldn’t be committed to the Git repository. These might include build artifacts like object and compiled code, dependency caches, runtime files such as logs, temporary or lock files, IDE or editor-specific files, and hidden OS files like Thumbs.db
or .DS_Store
.
I often see entries like .DS_Store
or .idea
added directly to a project’s .gitignore
, but this isn’t best practice. Not every developer uses the same tools or operating system, and maintaining a growing list of personal or environment-specific files in a shared repository can quickly become messy. The more appropriate approach — and one that should be considered a development standard — is to keep project-level .gitignore
files focused solely on files relevant to the project. For everything else — your IDE, your OS, and your personal workflow — Git allows you to set up a global ignore file that applies across all your projects.
To setup a file with a list of items which should be ignored globally on your local system:
git config --global core.excludesfile ~/.gitignore_global
To view the currently set file:
git config --get core.excludesfile
My current file for use on macOS:
# General files .DS_Store .AppleDouble .Apple Double .LSOverride # Thumbnail cache files ._* Thumbs.db # Custom icon file (which ends with \r), but not other icon* entries Icon? ![iI]con[_a-zA-Z0-9] # Files which can be in root of an external volume .com.apple.timemachine.donotpresent .DocumentRevisions-V100 .fseventsd .Spotlight-V100 .TemporaryItems .Trashes .VolumeIcon.icns # Possible directories on a remote AFP share .apdisk .AppleDB .AppleDesktop .Apple Desktop Network Trash Folder Temporary Items # Application specific files/directories .idea/ .vscode *.code-workspace # Local WIP and Notes /_*.md /_ToDo /_Old /_Open /_WIP # Temporary test files /t /t.* /t-* /t[0-9] /t[0-9].*