git
gitignore
configuration
version control
file management

How do I configure git to ignore some files locally?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

Local-only ignore behavior in Git depends on whether the file is tracked. For untracked files that only you want to ignore, use .git/info/exclude; for tracked files with local modifications, the answer is different and comes with tradeoffs.

Ignore Untracked Files Only on Your Machine

If the file is not tracked and you do not want to commit an ignore rule to the repository, add the pattern to .git/info/exclude:

bash
printf '%s\n' '.env.local' 'notes.txt' >> .git/info/exclude

This file behaves a lot like .gitignore, but it is local to your clone and is not committed to the repository. It is the cleanest answer for developer-specific files such as local notes or machine-specific config files that should stay untracked.

Use a Global Ignore for Repeated Personal Patterns

If the same local patterns apply across many repositories, configure a global ignore file:

bash
git config --global core.excludesfile ~/.gitignore_global
printf '%s\n' '.DS_Store' '*.swp' >> ~/.gitignore_global

This is useful for editor temp files, OS metadata files, and other personal noise that should never show up in any repository.

Tracked Files Are Different

If the file is already tracked by Git, ignore files do not make Git forget changes to it. That is where many people get confused. For tracked files, you have a few options, none of them perfect:

  • stop tracking the file and replace it with a template file committed to the repo
  • use git update-index --skip-worktree <file> for local divergence
  • use git update-index --assume-unchanged <file> only with care

For example:

bash
git update-index --skip-worktree path/to/config.json

This tells Git to leave your local changes alone in many workflows, but it is not a permanent policy mechanism and can become confusing when the repository version changes later.

Prefer Repository Design Over Local Tricks

If many developers need local customization, the better repository design is usually:

  • commit config.example.json
  • ignore config.json
  • generate or copy the local file during setup

That avoids relying on index flags that are easy to forget and hard for teammates to discover.

Know How to Undo Local Tracking Tricks

If you used skip-worktree or assume-unchanged, you should also know how to reverse it:

bash
git update-index --no-skip-worktree path/to/config.json
git update-index --no-assume-unchanged path/to/config.json

Without that, local ignore behavior can become mysterious months later when Git seems to stop noticing a file you expected it to track.

Use the Right Tool for the File State

A simple rule helps avoid confusion:

  • untracked local file: .git/info/exclude
  • personal noise across many repos: global ignore file
  • tracked shared config problem: redesign the repository layout

That framing is more reliable than trying to force one ignore mechanism to solve every case.

Common Pitfalls

  • Adding a tracked file to .gitignore and expecting Git to stop reporting its changes. Ignore rules mainly affect untracked files.
  • Using skip-worktree as if it were a team policy. It is only a local index hint.
  • Forgetting that .git/info/exclude is local to one clone and will not help teammates.
  • Using assume-unchanged for actively edited files. It is easier to misuse than many people realize.
  • Solving a shared config problem with local hacks when the repository should really use template files and documented setup steps.

Summary

  • For local untracked files, use .git/info/exclude.
  • For personal patterns across many repositories, use a global ignore file.
  • Ignore rules do not solve tracked-file changes.
  • For tracked files, skip-worktree and similar flags are local workarounds, not ideal long-term design.
  • If local configuration is common, restructure the repository around template files instead of relying on hidden local state.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.