Search code examples
gitgitignore

Git: Ignoring Version-Controlled Files


The .gitignore file is very useful in ignoring some of the files that we don't want to control. Unfortunately, it cannot be used when the file is already under version control. For example, my .gitignore (which is already added to git) file might be different than what my coworker wants it to be (e.g. I want to ignore Vim files). Whenever I make changes to this file, git shows it as a modified file. So my questions:

  1. Is there any way to ignore changes for a certain file, which is already controlled by Git?!
  2. Is there any way to commit these changes, but keep it for myself only? Obviously, I don't want to use a branch, because I am working on a certain branch.

Solution

  • If you want to exclude files that are specific to your process (such as Vim temporary files), edit the (local) file .git/info/exclude and add your exclusion patterns there. This file is designed for developer-specific exclusions rather than .gitignore, which is designed for project-wide exclusions.

    The short summary is, everybody should agree on what is added to .gitignore. For files where you don't agree, use .git/info/exclude.