# Choose global, local, or repository Git ignore rules

Canonical: https://githtml.com/guides/git-global-ignore-versus-repository-ignore
Published: 2026-11-23
Publisher: WaveTech LLC / gitHtml

Use a committed .gitignore for exclusions that apply to everyone working on the project. Use the repository’s info/exclude for local-only exclusions in that checkout, and a global excludes file for personal patterns across repositories. These mechanisms affect untracked files; none removes already tracked content from history or protects an exposed secret.

## Match the rule’s audience

A shared build directory usually belongs in .gitignore because every contributor should avoid committing it. A personal editor’s temporary files may belong in your global excludes file because they follow your tools across projects. A one-off local scratch file can belong in that checkout’s info/exclude. Choosing the right audience keeps the repository’s policy understandable.

Global exclusions can also create surprises. If your personal rules ignore a filename that is legitimate source in another project, you may never notice that the file is absent from history. Avoid broad names and prefer patterns specific to disposable tool artifacts. A local convenience should not make the project depend on files that only happen to exist on your machine.

## Inspect current configuration before adding another file

Check whether core.excludesFile is already configured and where that setting comes from. Use your editor to inspect the referenced file without replacing existing entries. The info/exclude path can be located through Git rather than assuming .git is always a directory. These inspection commands do not alter tracking or remove files.

1. Add project-wide rules only when teammates should inherit them, and review the resulting .gitignore change like any other configuration change.
2. Keep checkout-specific notes out of shared policy when they are merely your local workflow, but make sure important knowledge is not hidden in an untracked file.

````shell
git config --show-origin --get core.excludesFile
git rev-parse --git-path info/exclude
git check-ignore -v -- scratch-notes.txt
git status --short --ignored
````

## Test the actual path and preserve history expectations

After editing a rule, run check-ignore against the exact file and read the reported source. This distinguishes a repository rule from a global one and avoids duplicating patterns across several files. If the path is already tracked, address tracking separately; editing ignore files will not stop Git from reporting changes to a tracked file.

For a concrete case, ignore a personal editor swap suffix globally but keep the project’s generated package directory in its committed .gitignore. A teammate then receives the reproducibility policy without inheriting your editor preferences. If a fresh clone fails because a required file was ignored locally, correct the rule and commit the legitimate source deliberately. The success criterion is a repository that contains everything needed for the project while excluding truly disposable or private local artifacts.

When debugging a missing file with a teammate, compare the source reported by check-ignore on both computers. Different personal rules can explain different status output for identical paths.

## Sources and further reading

- [Git reference: gitignore](https://git-scm.com/docs/gitignore)
- [Git reference: git-config](https://git-scm.com/docs/git-config)
- [Git reference: git-check-ignore](https://git-scm.com/docs/git-check-ignore)

## Related guides

- [Understand HEAD, HEAD~1, and HEAD^2 in Git](https://githtml.com/guides/git-head-tilde-caret-parent-revisions)
- [Initialize Git in an existing project safely](https://githtml.com/guides/git-initialize-existing-project-safely)
- [List local and remote-tracking Git branches](https://githtml.com/guides/git-list-local-remote-tracking-branches)
- [Read a Git history graph without confusing lanes](https://githtml.com/guides/git-log-graph-read-branch-history)

Editorial approach: https://githtml.com/guides/about
