Setting Up Global Git Ignore Rules

  • Post category:Development
  • Reading time:2 mins read
  • Post comments:0 Comments
You are currently viewing Setting Up Global Git Ignore Rules

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

Personal Tip

If you find you need to keep local documentation and planning notes in the root of the project, but you want to keep them out of source control, you can standardize on a naming scheme which works for you and add them to your global gitignore file. For example, you could use file names such as _ToDo, _Old, _Open and _WIP (i.e. Work-in-Progress) across your projects. To support more complex documentation for projects which need it, you may also want to ignore files in the root which match _*.md.

To support creating quick, temporary test scripts, you may also consider ignoring t, t.*, t-*, t[0-9] and t[0-9].* files.

Such a scheme can help you avoid committing scratch work and personal files.

My current file for use on macOS, which you should tailor to match your own tools and habits:

# 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].*

Common editor, IDE and related tool file settings (to put in a global gitignore file):

  • .vscode, .code-workspace – VS Code
  • .idea/ – PhpStorm and other JetBrain
  • .phpactor.json – Phpactor
  • .fleet – JetBrains Fleet (lightweight IDE)
  • *.sublime-project, *.sublime-workspace – Sublime Text
  • .project, .settings – Eclipse IDE
  • nbproject/, – Netbeans IDE
  • tmproj – TextMate Editor
  • *.swp, *.swo, *~ – vi and vim
  • *.diff – git diff, DiffMerge, Kaleidoscope, GNU Diffutils, etc.
  • *.orig, *.rej – git apply/merge, patch utility, etc.
  • *.esproj – JavaScript Project System (JSPS) in Visual Studio
  • .zed – Zed (collaborative code editor built by the creators of Atom)
  • *.komodoproject, .komodotools – Komodo Edit
  • dwsync.xml, _notes/ – Adobe Dreamweaver

Common per-project settings (to keep in a project’s .gitignore):

  • General
    • .env, .env.local, .env.backup
    • .secrets/
    • *.log – log files
    • /composer.lock – when creating a composer package rather than an app
  • Dependencies
    • /vendor/, /auth.json – Composer
    • node_modules/ – Node
    • *.sass-cache – Sass/SCSS
  • Laravel build/runtime
    • /public/build, /public/hot, /public/storage
    • /storage/*.key, /storage/logs/*.log, /storage/pail
    • /storage/app/public, /storage/framework/*
  • Laravel Nova
    • /nova-components/vendor/
    • /nova-components/*/dist/
    • /nova-components/*/node_modules/
    • /nova-components/*/vendor/
  • Laravel Homestead
    • Homestead.json
    • Homestead.yaml
  • Test and Coverage
    • .phpunit.results.cache
    • .phpunit.cache/
    • coverage/
  • Other Source Control (normally not expected in Git projects
    • .svn/ – SVN (Subversion)
    • .CVS/ – CVS (Concurrent Versions System)
    • .hg/ – Mercurial

Leave a Reply