Ignore files without modifying .gitignore

2022-03-13 1 min read

The .gitignore file is also tracked so you've to expose a list of your ignored files when you added them to the .gitignore file. This may not be what you want.

The exclude file

In the git folder, there's a file called exclude at .git/info/exclude. This file just works like the .gitignore file but without being tracked. You can ignore untracked files with this file without exposing them.

When the exclude file isn't enough

The exclude file does the job if you only want to ignore untracked files. But what if those files are already tracked? In such cases, you can use the below commands to ignore a specific file or path.

git update-index --assume-unchanged file/path/FILE.md

To undo:

git update-index --no-assume-unchanged file/path/FILE.md

To create aliases for these commands:

.gitconfig
[alias]
    hide = update-index --assume-unchanged
    unhide = update-index --no-assume-unchanged
Date: 2022-03-13
Categories: development
Tags: git