Mutludev

Git Tips Exclude files locally

Recently, I ran into an annoying issue while working on a project. The repository has a configuration file that's checked into Git, but I need to modify it to suit my development environment. Unfortunately, since the file is tracked, Git constantly flags it as modified. Every time I want to pull new changes, I have to stash and pop my local changes, and it becomes annoying fast.

Fortunately, Git has a local exclude file that can help. Here's how to use it:

  1. Open the .git/info/exclude file in your repository.
  2. Add the path to the file you want Git to ignore, just like you would in a .gitignore file.

That’s it. Git will now locally ignore changes to that file. This tip really worked for me, so I'm sharing it here in case it works for you as well, and in case I need it in the future.