It can be useful to exclude a file in local repo without using a .gitignore
file, which is a best practice if the file is one you don't expect other users to generate themselves.
Add it to:
.git/info/exclude
You can also add this git alias, by adding it to your .gitconfig file in the [alias] section:
exclude = !sh -c 'echo "$1" >> .git/info/exclude'
thus:
git exclude SOME_FILE
An interesting alternative is to use the git update-index --skip-worktree SOME_FILE
, which will lock the file into its current state and git
will ignore future changes to it. See https://compiledsuccessfully.dev/git-skip-worktree/