📝
This post is part of my “Shorts” series, where each post is concise and hyper-focused on a single concept.

In the previous post, I mentioned that you can use .git/info/exclude file as your personal local .gitignore. However, it only works on files that are untracked, i.e., which have never been tracked using git add.

How to locally ignore tracked files?

  • Run this command: git update-index --assume-unchanged <filename>.

For example, if your filename is called my-awesome-file.txt, then run the command:

git update-index --assume-unchanged my-awesome-file.txt

Breaking down the command

  • update-index: Ask git to update its index, that is used to track changes to existing files and creation of new files.
  • --assume-unchanged: Ask git to assume that the file will be unchanged from now. Remove it from the index.

Caveat

If someone else modifies the file in the remote repository:

  • You will receive the updated file content after running git pull.
    • If you have made changes to the file before running git pull, git will most probably throw an error warning you that your local changes will be lost.
  • The file will be added to the index again, and thus tracked.

How to undo? Re-adding the file to index

git update-index --no-assume-unchanged <filename>

Sources