Last Updated: August 01, 2023
·
11.73K
· csquirrel

Git: Temporarily ignoring files

On some occasions you may need to ignore few files without touching 'gitignore' (e.g. local configuration). To achieve that you simply issue following command:

git update-index --assume-unchanged <file_to_ignore>

From now on the file will be excluded from the list of changes. You can safely use 'git add'. To see what's ignored use:

git ls-files -v | grep ^h

To stop ignoring file you simply execute:

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

You may find alisases more handy to use. Add them to either ~/.gitconfig (global) or .git/config (repository)

[alias]
        ignore = !git update-index --assume-unchanged 
        unignore = !git update-index --no-assume-unchanged
        ignored = !git ls-files -v | grep ^[a-z]

7 Responses
Add your response

I would prefer skip aliases instead of ignore because I use ignore command to add file to .gitignore.

over 1 year ago ·

Thx for sharing those useful tips!

I've the problem that I get "fatal: Unable to mark file ..." when I try to ignore a file. What could be the problem?

over 1 year ago ·

@daniel-marschner Is the file in the repo yet? The update-index action only works on files that are in your repo. If its not in the repo yet, you can add it to .gitignore.

over 1 year ago ·

This didn't work for me when I added it to .gitconfig but does work when added to my .bashrc with some minor changes - could be the setup at work.

But thank you for sharing this - its a great tip.

over 1 year ago ·

@juanfernandes: That's bizzare because these are git alias definitions. They shouldn't be processed by shell (.bashrc) but by git itself (.gitconfig).

over 1 year ago ·

@csquirrel Oh really. That is weird as all my git aliases are in my .bashrc file

over 1 year ago ·

The aliases are for Git itself, as in "git [alias]".

over 1 year ago ·