3 ways to make git ignore your changes

1. .gitignore: ignore for everyone

This file, .gitignore, when created at the root of your repository, can be filled with patterns of paths of files to be ignored:


There is a useful repo with a lot of pre-made .gitignore files for different languages. These templates spare you of necessity to build one yourself:

GitHub - github/gitignore: A collection of useful .gitignore templates
A collection of useful .gitignore templates. Contribute to github/gitignore development by creating an account on GitHub.

Note that .gitignore only works for files that have not yet been committed. If you want to start ignoring a committed file, you have to delete it from history first:

$ mv .idea .idea.tmp
$ git rm .idea
$ git commit -m "Delete .idea/"
$ mv .idea.tmp .idea
How to start ignoring a committed ".idea" directory (works for files the same way)

More on .gitignore:

Git - gitignore Documentation

2. .git/info/exclude: ignore only for me

This file has the same syntax and the same effect as .gitignore with one big difference: it is not shared between users of the repository. You can use it to ignore files that are local and specific to your work and might not be useful for other developers.

I usually put this pattern in it:


This way I can create temporary markdown notes (for example, task.ignore.md) or scripts (like test.ignore.py) without risking committing them by mistake.

3. skip-worktree: ignore changes to a committed file

This one can be useful, for example, if there is a config file committed into the repository, but you want to personalize it to your own taste without pushing these edits to everyone else.

Marking the file as skipped will make git stop synchronizing it with the repo's history:

git update-index --skip-worktree .vscode/config.json

To undo this use --no-skip-worktree:

git update-index --no-skip-worktree .vscode/config.json

Note that skip-worktree doesn't work with directories or patterns, it only accepts paths to specific files.