DEV Community

Cover image for git assume-unchanged. For when you want git to ignore an edit for a while
Nick Raphael
Nick Raphael

Posted on

git assume-unchanged. For when you want git to ignore an edit for a while

Quite often, I find myself in the situation where I've updated a file but I don't want git to track that change. Usually this is a temporary update to a config file.

For example, right now I'm running my webapi locally and I've updated my angular environment.ts file to point locally. I'll be working like this for a few days and I want to regularly commit and push my changes. But I don't want to commit the changes to environment.ts. I like to do git add . to include all my updates but it's annoying to have a single file that I don't want to include.

Turns out, unsurprisingly, there is a handy git command for this...

git update-index --assume-unchanged "somewhere/environment.ts"
Enter fullscreen mode Exit fullscreen mode

If you run a git status you will see that git is no longer aware of the edit. We can now do...

git add .
git commit -m "I did stuff and stuff"
git push
Enter fullscreen mode Exit fullscreen mode

To undo this, we simply...

git update-index --no-assume-unchanged "somewhere/environment.ts"
Enter fullscreen mode Exit fullscreen mode

I do this whenever I make an update that I know I won't want to push.

Top comments (2)

Collapse
 
gilbarbara profile image
Gil Barbara

Awesome! 👍🏻

Collapse
 
masaeedu profile image
Asad Saeeduddin

This is lifechanging, thank you!