How do repository-level and global Git ignore files differ?
Quick answer
Use a repository’s .gitignore for patterns the project team should share, such as generated files everyone wants ignored. Use .git/info/exclude for a pattern that applies only to your copy of one repository. Use a global excludes file, configured with core.excludesFile, for personal patterns you want ignored across repositories, such as editor backups. Choose the scope based on who should receive the rule. [S1]
The question, the details, the next step.
A practical checklist
Ask who should receive the rule: the project team, only this repository, or you across repositories.
Put team-wide patterns in a repository
.gitignorethat can be version-controlled and shared.Use
.git/info/excludefor patterns limited to your local copy of one repository.Use a configured global excludes file for personal patterns that should apply generally.
If a pattern is duplicated, review the documented precedence:
.gitignore, theninfo/exclude, then global excludes.
A few more useful answers
Will a rule in `.git/info/exclude` be shared with someone who clones the repository?
It is intended for patterns specific to one repository that do not need to be shared. Use a project .gitignore when the rule should travel with the repository. [S1]
Where is Git’s global excludes file by default?
Git documents $XDG_CONFIG_HOME/git/ignore as the default. If XDG_CONFIG_HOME is unset or empty, the documented default is $HOME/.config/git/ignore. [S1]
Which ignore scope takes precedence when patterns overlap?
The documented order is per-directory .gitignore rules, then .git/info/exclude, then the configured global excludes file. [S1]
Sources
References used for this guide.
- [S1] Git ignore documentation: shared and local ignore scopes git-scm.com · Checked
