Recent chats
ASKGEEZ Q&A GUIDETechnology & devices

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]

LET’S WORK THROUGH IT

The question, the details, the next step.

Question

I have generated output, an editor backup, and one temporary file I made in a particular checkout. Which ignore file should each go in?

Geez

Choose based on who should get the rule. If the generated output is something the project team should ignore, put its pattern in a repository .gitignore and commit that file so the rule can be shared. Put the editor backup pattern in your global excludes file if you want the same personal preference across repositories. Put the one-off temporary file’s pattern in that repository’s .git/info/exclude if teammates should not receive it. [S1]

For example, build-output/ might belong in the project file if everyone should ignore that directory. A personal pattern such as *.editor-backup could go in the global file. A pattern for scratch-notes.txt created just for your checkout could go in .git/info/exclude.

Follow-up question

What makes .gitignore different from .git/info/exclude if both apply inside the repository?

Geez

The practical difference is whether the rule is shared. A project .gitignore is intended to be version-controlled and shared with others through the repository. .git/info/exclude is for patterns specific to your local repository that do not need to be shared. For instance, use .gitignore for generated files the team agrees to ignore, and info/exclude for a scratch file that only you need to ignore in this checkout. [S1]

Before adding a pattern to a shared file, ask whether another person working on this project should receive the rule. If not, a local or personal file is usually a better fit.

Follow-up question

I want editor backups ignored in every project I work on. Where does the global file live, and how do I set its location?

Geez

Configure Git’s core.excludesFile setting to point to your global ignore file, then put your personal patterns in that file. For example, you can set a location with git config --global core.excludesFile /path/to/ignore, replacing /path/to/ignore with the path to your file. [S1]

Git documents the default location as $XDG_CONFIG_HOME/git/ignore; if XDG_CONFIG_HOME is unset or empty, the documented default is $HOME/.config/git/ignore. [S1] A pattern such as *.editor-backup could go in that file if it matches the backup filenames you use.

Follow-up question

What if the same pattern appears in more than one place? Is there a simple way to decide scope without overthinking it?

Geez

Git’s documented precedence is: per-directory .gitignore rules are considered above .git/info/exclude, which is above the configured global excludes file. [S1] That ordering describes precedence, not who should own a rule; choose its location based on who should receive it.

For example, a team-wide generated directory could go in the project .gitignore, a one-checkout scratch file in .git/info/exclude, and a personal editor-backup pattern in your global file. These are placement examples, not universal filename recommendations; the right pattern depends on your project and files. [S1]

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 .gitignore that can be version-controlled and shared.

  • Use .git/info/exclude for 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, then info/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.

  1. [S1] Git ignore documentation: shared and local ignore scopes
    git-scm.com · Checked

YOUR QUESTION. YOUR DETAILS.

Let’s work through your situation.

Get a tailored answer or help with your next task. Starts at $1, with a quote before you pay.

Ask your own question
← Back to Geez at Work