Skip to content

Instantly share code, notes, and snippets.

@ChristopherA
Last active September 30, 2022 16:12
Show Gist options
  • Save ChristopherA/810c9711ec27d66e4d42f1c719cf3a7a to your computer and use it in GitHub Desktop.
Save ChristopherA/810c9711ec27d66e4d42f1c719cf3a7a to your computer and use it in GitHub Desktop.
git exclude vs .gitignore #git #worktree

Git exclude vs .gitignore

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment