How to Hide Local Git Changes Without Ignoring Files

TLDR; git config --global alias.hide 'update-index --assume-unchanged' git config --global alias.unhide 'update-index --no-assume-unchanged' git config --global alias.hidden '! git ls-files -v | grep '^h' | cut -c3- Motivation Has this ever been you problem. You frantically type some code and you have changes in 10 of files and you only need to commit just one of them and all the other files are configuration files or something else that's unique to your machine and this doesn't need to go to the source control. Well, recently I was going through the same problem. I was using a windows machine and my co-workers with a mac. All of them use mac therefore the npm-scripts, linting configuration, dockerfiles etc... are only mac specific. Therefore, I have to change them to work for my machine. This doesn't need to be pushed to source control. And they are inheritly against choosing an agnostic solution. Therefore, I have almost 10-12 config files which are specific to my machine. But this messes up with my git status. I wondered is there a way out of this mess. Then Searching through the Internet I found update-index which is a command in git, it helped me with my problem therefore, I am sharing this with you guys. Solution There is a concept of index in git. Basically you can think of index as a snapshot of the repository which git tracks. Basically any command like status, add ..etc will use this index to perform operations with git. So, we just need to update this index. And git generously provides us with this command called update-index. Which we can use to udpate the index of the git. This inturn will make the changes doesn't appear in git status or anything similar. Which is exactly what we need. git update-index --assume-unchanged file.txt Ok, this is all great but what if, I want the changes in the file to be commited how to do that ? As we know that we have updated the index to reflect that the file has no changes we can make sure to say that the file has changes. That can be done in the following way: git update-index --no-assume-unchanged file.txt This will ensure that this file is tracked by git. But what if you want to see the hidden files ? git ls-files -v | grep '^h' | cut -c3- Add the commands as aliases git config --global alias.hide 'update-index --assume-unchanged' git config --global alias.unhide 'update-index --no-assume-unchanged' git config --global alias.hidden '! git ls-files -v | grep '^h' | cut -c3- Usage Rather than typing the long command git update-index --assume-unchanged file.txt as we have already added this as alias called hide we can do something like this: git hide file.txt # same as git update-index --assume-unchanged file.txt git unhide file.txt # same as git update-index --no-assume-unchanged file.txt git hidden # same as git ls-files -v | grep '^h' | cut -c3- Refrences update-index docs. Inspired from github

Mar 16, 2025 - 10:09
 0
How to Hide Local Git Changes Without Ignoring Files

TLDR;

git config --global alias.hide 'update-index --assume-unchanged'
git config --global alias.unhide 'update-index --no-assume-unchanged'
git config --global alias.hidden '! git ls-files -v | grep '^h' | cut -c3-

Motivation

Has this ever been you problem. You frantically type some code and you have changes in 10 of files and you only need to commit just one of them and all the other files are configuration files or something else that's unique to your machine and this doesn't need to go to the source control.

Well, recently I was going through the same problem. I was using a windows machine and my co-workers with a mac. All of them use mac therefore the npm-scripts, linting configuration, dockerfiles etc... are only mac specific. Therefore, I have to change them to work for my machine. This doesn't need to be pushed to source control. And they are inheritly against choosing an agnostic solution. Therefore, I have almost 10-12 config files which are specific to my machine. But this messes up with my git status. I wondered is there a way out of this mess. Then Searching through the Internet I found update-index which is a command in git, it helped me with my problem therefore, I am sharing this with you guys.

Solution

There is a concept of index in git. Basically you can think of index as a snapshot of the repository which git tracks. Basically any command like status, add ..etc will use this index to perform operations with git. So, we just need to update this index. And git generously provides us with this command called update-index. Which we can use to udpate the index of the git. This inturn will make the changes doesn't appear in git status or anything similar. Which is exactly what we need.

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

Ok, this is all great but what if, I want the changes in the file to be commited how to do that ? As we know that we have updated the index to reflect that the file has no changes we can make sure to say that the file has changes. That can be done in the following way:

git update-index --no-assume-unchanged file.txt

This will ensure that this file is tracked by git.

But what if you want to see the hidden files ?

git ls-files -v | grep '^h' | cut -c3-

Add the commands as aliases

git config --global alias.hide 'update-index --assume-unchanged'
git config --global alias.unhide 'update-index --no-assume-unchanged'
git config --global alias.hidden '! git ls-files -v | grep '^h' | cut -c3-

Usage

Rather than typing the long command git update-index --assume-unchanged file.txt as we have already added this as alias called hide we can do something like this:

git hide file.txt # same as git update-index --assume-unchanged file.txt
git unhide file.txt  # same as  git update-index --no-assume-unchanged file.txt
git hidden # same as git ls-files -v | grep '^h' | cut -c3-

Refrences