Overview
Adding a .gitignore
file to a project allows you to exclude certain files and directories from being tracked by git. However, it can be tedious to repeatedly add default directories like .idea
generated by IDEs to .gitignore
for each new project. This article explains how to apply .gitignore
settings globally across all projects.
Applying gitignore Globally
Git by default checks for ignore settings in ~/.config/git/ignore
. Therefore, by placing your ignore configurations in this file, you can have them applied to all your projects.
While it’s common to create a .gitignore_global
and register it under core.excludesfile
, this method requires unnecessary configuration in .gitconfig
, which is why the approach described here is recommended.
Steps to Apply gitignore Globally
Create a Directory for Ignore File
Create a directory to store your ignore file, if it doesn’t already exist:
|
|
Create and Configure the Ignore File
Create the ignore file and write the patterns for files and directories you want to ignore globally:
|
|
Example of what to include:
|
|
Applying the Ignore Settings
These settings will now automatically apply to all projects managed under your user account. If there are already tracked files you wish to ignore, use git rm --cached
to stop tracking them without deleting the files.
Reference
By following these steps, you can efficiently manage your ignore settings across all your git projects without having to replicate configurations in each project repository.