Can I ignore files locally without polluting the global git config for everyone else? I have untracked files that are spam in my git status but I don't want to commit git config changes for every single little random untracked file I have in my local branches.
Use Git update-index to ignore changes To resume tracking, run the git update-index command with the --no-skip-worktree flag. Or, you can temporarily stop tracking a file and have Git ignore changes to the file by using the git update-index command with the assume-unchanged flag.
A gitignore file specifies intentionally untracked files that Git should ignore.
From the relevant Git documentation:
Patterns which are specific to a particular repository but which do not need to be shared with other related repositories (e.g., auxiliary files that live inside the repository but are specific to one user's workflow) should go into the
$GIT_DIR/info/exclude
file.
The .git/info/exclude
file has the same format as any .gitignore
file. Another option is to set core.excludesFile
to the name of a file containing global patterns.
Note, if you already have unstaged changes you must run the following after editing your ignore-patterns:
git update-index --assume-unchanged <file-list>
Note on $GIT_DIR
: This is a notation used all over the git manual simply to indicate the path to the git repository. If the environment variable is set, then it will override the location of whichever repo you're in, which probably isn't what you want.
Edit: Another way is to use:
git update-index --skip-worktree <file-list>
Reverse it by:
git update-index --no-skip-worktree <file-list>
Update: Consider using git update-index --skip-worktree [<file>...]
instead, thanks @danShumway! See Borealid's explanation on the difference of the two options.
Old answer:
If you need to ignore local changes to tracked files (we have that with local modifications to config files), use git update-index --assume-unchanged [<file>...]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With