Last Updated: September 09, 2019
·
39.14K
· diasjorge

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

6 Responses
Add your response

I'd rather use
git update-index --skip-worktree SOME_FILE

Works better in most cases.

over 1 year ago ·

@sujaykrishna Why is your case better than the method in the protip?

I didn't know any of those... It's just honest curiosity =)

over 1 year ago ·

@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.

over 1 year ago ·

@sujaykrishna Thanks for the all the info =)

over 1 year ago ·

@sujaykrishna that's why the tip is about excluding files in your local copy.

over 1 year ago ·

@diasjorge Your intention was unclear.
If your title was Excluding untracked files from git locally I'd never have made that comment. :)

over 1 year ago ·