How to exclude or ignore some files from git commit

Some time we required to remove some files from git modified files because those files are not required to push on every time. Below command for very useful to ignore files from a track or modified files.


You want to automatically exclude some files from git commit because they have done some changes that are only meaningful to the local system and it’s not related the other developers.

Below command very useful for remove or exclude files from git commit


Modifies the index or directory cache, this command will update your local git config index and it’s not updated remote repository, it will update the only your local branch


Set “–assume-unchanged” to a path to exclude to check on git commit and it will exclude your file from git commit.

You will need to use the git update-index and –assume-unchanged to exclude files from git commit.

Syntax :

git update-index --assume-unchanged filepath
git update-index --assume-unchanged default/config.php


I have been working on Drupal project and it’s on bitbucket and it’s configured to different server, and they mentioned main server config and DB details on settings.php files but my local configurations and database details different from main server so here I can use the below command to exclude my local copy of settings.php file from git commit.

git update-index --assume-unchanged sites/default/settings.php

All set, if you want to know which files are currently excluded from git commit, here below command for display list of files that automatically hide from git, these hide or exclude by using assume unchanged keyword on git “–assume-unchanged”.


git ls-files -v | grep -e "^[hsmrck]"

Simply copy command and paste in terminal and it will display list files exclude from git commit, make sure run this command on your project path.