Excluding files from git locally
If you ever want to ignore a file from git, but don't want to add it to the .gitignore file, you can do it on your local copy by adding it to the file ".git/info/exclude"
I've setup an alias to do so, just add this to your .gitconfig file under the [alias] section
exclude = !sh -c 'echo "$1" >> .git/info/exclude' -
Then you can execute:
git exclude SOME_FILE
Written by Jorge Dias
Related protips
6 Responses
I'd rather use
git update-index --skip-worktree SOME_FILE
Works better in most cases.
@sujaykrishna Why is your case better than the method in the protip?
I didn't know any of those... It's just honest curiosity =)
@couto The actual purpose of .git/info/exclude is local repo specific ignore. It is not for tracked files.
Chk out the Repo exclude section of https://help.github.com/articles/ignoring-files it is to be used for files "that you don't expect other users to generate".
For tracker files the update-index functionality works better.
Also see http://www.kernel.org/pub/software/scm/git/docs/git-update-index.html#_skip_worktree_bit for more info on how skip-worktree works and why it is different from the assume-unchanged bit.
@sujaykrishna Thanks for the all the info =)
@sujaykrishna that's why the tip is about excluding files in your local copy.
@diasjorge Your intention was unclear.
If your title was Excluding untracked files from git locally I'd never have made that comment. :)