How to configure Git to Ignore some Files Locally without editing the Global Git Config

Git is a version control system that helps you track changes to your code. It also allows you to ignore certain files from being tracked by Git. This can be useful for files that you don’t want to be committed to the repository, such as temporary files, build artifacts, or IDE configuration files.

By default, Git uses a global .gitignore file to ignore certain files. This file is located in your home directory and is shared by all of your Git repositories. This can be inconvenient if you want to ignore different files in different repositories.

To ignore files locally without polluting the global git config, you can create a file called .git/info/exclude in the root directory of your repository. This file is specific to your repository and will not be shared with other users.

To add a file to the .git/info/exclude file, simply list the path to the file relative to the root of your repository. For example, to ignore the file my-file.txt, you would add the following line to the .git/info/exclude file:


You can also use glob patterns to match multiple files or directories. For example, to ignore all files with the .tmp extension, you would add the following line to the .git/info/exclude file:


To ignore the entire node_modules directory, you would add the following line to the .git/info/exclude file:


Once you have added the files that you want to ignore to the .git/info/exclude file, you need to tell Git to reload the ignore rules. You can do this by running the following command:

git update-index --refresh

After you have run the git update-index --refresh command, the files that you have added to the .git/info/exclude file will no longer be tracked by Git.

I hope this helps! Let me know if you have any other questions.

Leave a Reply