Git – Ignore changes on a tracked file

Assume you Git repository contains the following 3 files.

  • file.txt
  • init.conf


i want to retain the init.conf in the repository for initial checkout. After that, ignore further changes which is made on the local branch.

In the above case, .gitignore doesn’t work because it is only for untracked file which means you have to remove it that file from the Git repository.

Here is a workaround which i found on StackOverflow. On your local branch, execute the following command to set the assume-unchanged bit on a particular <file>.

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


This will make your local branch ignore any changes on your tracked files. The drawback is any update of that file on the remote branch would be invisible to your local branch too.

To revert the index, you can use do the following.

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


To list out those files which the assume-unchanged bit is set, use the following.

git ls-files -v | grep ^h


Done =)



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.