Ignoring git changes locally

It is well known that in a git repository we can use a .gitignore file to skip tracking files we do not want to push to the remote repository. If a file matches a .gitignore pattern, it will not appear in git status when you want to add its changes to a commit.

They are typically used to ignore directories where dependencies are installed (e.g. the virtualenv for Python projects, usually found in .venv), temporary files generated by the interpreter or compiler, IDE-specific files, and so on.

They are so common that GitHub offers gitignore templates curated for different programming languages, and tools such as uv init generate a basic .gitignore as part of the boilerplate.

A .gitignore is part of the project (it is committed), and it is important to keep it in the repository so that every collaborator shares the same configuration.

But what if we want to ignore files only locally?

There are two ways to do that:

  • .git/info/exclude inside the project, which uses the same format, is not versioned in the repository, and affects only the local clone.
  • $HOME/.config/git/ignore does the same thing but applies to all of the user's repositories.

Want a few extra tips? If you want to list every ignored file in the repo:

git status --ignored

If you have complex patterns or several .gitignore files at different levels, you can see which configuration is ignoring which file with:

git check-ignore -v <file>

Comments

Comments powered by Disqus