1. .gitignore: ignore for everyone
.gitignore, when created at the root of your repository, can be filled with patterns of paths of files to be ignored:
*.pyc .idea/ .vscode/
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:
.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:
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
git update-index --no-skip-worktree .vscode/config.json
skip-worktree doesn't work with directories or patterns, it only accepts paths to specific files.