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.
14 Answers
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>

- 20,752
- 7
- 62
- 64

- 171,072
- 38
- 269
- 275
-
If GIT_DIR is undefined it's just the path to the .git repository. – Josh Lee Nov 18 '09 at 01:42
-
6This doesn't appear to work. Git still sees the changes and asks me to commit them. – Adam Grant Mar 26 '13 at 16:30
-
240As a note, make sure to run ```git update-index --assume-unchanged [
...]``` after making the addition to the exclude file. The changes won't be picked up until then. – tollmanz Mar 30 '13 at 16:05 -
36I did not need to run 'git update-index ...' for the changes to take effect using git 1.7.9.5. – Jeffrey Martinez Dec 09 '13 at 05:30
-
1Confirmed. @JeffreyMartinez was correct. I did not need to run update-index on OS X with git version 1.8.3.4 (Apple Git-47). – CatDadCode Dec 17 '13 at 00:18
-
46You only need to use git update-index if you've already made a change to the file and now want it to be ignored. If you change exclude prior to making the change, it's not necessary. – Brady Emerson Jun 24 '14 at 00:45
-
21While this stops the file from appearing as changed during commits like .gitignore, unlike ignored files, the file(s) will still be reset back to the repo version if you execute git reset --hard. – Brady Emerson Jun 24 '14 at 00:47
-
I needed to run update-index on git version 2.1.3 MacOSX – Michael Merchant Dec 02 '14 at 09:34
-
Is there any way to have some global ignore entries, so they apply to all my projects? – clarkep Dec 06 '14 at 03:47
-
23Per http://stackoverflow.com/questions/23097368/git-ignore-vs-exclude-vs-assume-unchanged and http://stackoverflow.com/questions/13630849/git-difference-between-assume-unchanged-and-skip-worktree/13631525#13631525, ``skip-worktree`` would likely be preferred to ``assume-unchanged``. – danShumway Jul 22 '15 at 02:39
-
1@pjc: look for _Patterns which a user wants Git to ignore in all situations_ [here](http://git-scm.com/docs/gitignore/2.7.0) – fscherrer Jan 08 '16 at 12:00
-
3For all the files in a directory: `git update-index --assume-unchanged mydir/**/*.*` – BenjaminGolder Jan 28 '17 at 01:37
-
2What happens when you `git pull` and there's a file with the same name as the file you're ignoring locally? – zok Jun 07 '17 at 08:56
-
1This doesn't work for untracked files. (git 2.13.5 on osx) – Terra Ashley Oct 04 '17 at 20:58
-
You guys keep saying that you have to run update-index if you have untracked changes, but I've just never found that to be the case. git status stops showing the files immediately after editing .gitignore or .git/info/exclude – iCodeSometime Jul 11 '18 at 00:57
-
3Please [don't use `assume-unchanged` this way](https://public-inbox.org/git/xmqqy4z5go1y.fsf@gitster.dls.corp.google.com/): 'Assume-unchanged should not be abused for an ignore mechanism. It is "I know my filesystem operations are slow. **I'll promise Git that I _won't_ change these paths**…" Especially, it is *not* a promise… that Git will always consider these paths are unmodified—if Git can determine a path… has changed without incurring extra `lstat(2)` cost, it reserves the right to report that the path *has been* modified (as a result, `git commit -a` is free to commit that change).' – ChrisGPT was on strike Apr 09 '19 at 20:22
-
Thanks for the great answer! I have a question for you. I am trying to remove a directory `./grids/` from my local laptop filesystem while not affecting the remote repository. I added `grids/*` to the `.git/info/exclude` file and tried removing one file in that directory with `git rm file_name`. However, the deletion is still committed to the repository. Am I doing something wrong or this does not work for deletion? – zyy May 13 '19 at 14:10
-
is there a way to make this work at a directory level? This only seems to work for individual files? I can't seem to ignore a whole directory... – Stuart Aug 09 '19 at 10:16
-
I've do it, and it also has showed in `git ls-files -v | grep ^h`, but git still ask me to commit when trying to git pull – Blackjack Oct 22 '19 at 16:16
-
5This doesn't work for me. Whenever I try and checkout a new branch I get `error: Your local changes to the following files would be overwritten by checkout: excluded-file`. – Declan McKenna Nov 07 '19 at 11:28
-
I've just added my file path to the .git/info/exclude file and it works. – Sabrina Dec 13 '19 at 12:51
-
`git update-index --assume-unchanged directory/ ` adding a forward slash(/) in the end worked for me. – Monir Khan Apr 02 '20 at 15:25
-
Is it possible to only ignore the wiles while "push" commands but not while "pull" commands? Basically I want my changes shouldn't get pushed but any changes in master can be pulled. – Arman Jul 08 '20 at 11:20
-
For users in Sourcetree, you may have to "refresh" the uncommitted files before these changes visually take hold. I did this by switching to a different repo and going back into my original. – Brett La Pierre Jun 03 '21 at 16:41
-
after I did `git update-index --skip-worktree
` and try to switch branch I get `Your local changes to the following files would be overwritten by checkout` even though `git stash` shows no changes. `git update-index --assume-unchanged ` doesn't help – klm123 Nov 12 '21 at 08:14 -
I don't suppose that it is possible to retrieve a list of what files in a repo I am ignoring after this? Currently I refresh myself with "history | grep worktree", and write down what files I've ignored. – Mongo0se May 26 '22 at 08:39
-
If you get **"fatal: Unable to mark file"** error message: look [here](https://stackoverflow.com/questions/8598937/git-update-index-assume-unchanged-returns-error/72911442#72911442) – Andrii Viazovskyi Jul 12 '22 at 07:50
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>...]
.

- 32,635
- 12
- 70
- 99

- 5,972
- 1
- 25
- 26
-
8Just to note, I added a file to $GIT_DIR/info/exclude (e.g., my-file.php) and then had to run ```git update-index --assume-unchanged my-file.php``` for it to start being ignored. Thanks for the tip! – tollmanz Mar 30 '13 at 16:04
-
84
-
20Just for clarification: assume-unchanged is for tracked files (exist in the repo)... OP was asking for UNtracked files, in which case `.git/info/exclude` is what you want (to avoid polluting the often shared and tracked .gitignore) – dyodji Jan 30 '14 at 01:56
-
1@Florian Sesser is it possible to do it for entire folder or multiple file in single command? – Mohamed Hussain Feb 16 '15 at 08:34
-
7According to http://stackoverflow.com/questions/23097368/git-ignore-vs-exclude-vs-assume-unchanged this is considered unsafe, and your files may still be committed if you're not careful. It's intended as a performance aid, not as a foolproof solution to this problem. – danShumway Jul 16 '15 at 23:16
-
Holy moly @danShumway, maybe all my stack overflow reputation is based on an answer that is wrong. OTOH, I do still not see another mechanism to stop git from bugging me not when I change files that are indexed. Also, please consider whether your comment might also be relevant to josh-lee's answer. – Florian Sesser Jul 20 '15 at 14:41
-
1Borealid's is the most complete answer to this online that I've found, so you have all of the same information as me at this point. This seems to be a really common misconception, in part because the original git documentation listed it as a viable method. From what I can tell, a fairly reasonable percentage of the web doesn't realize that, for example, this will get turned off whenever you pull a new version of the file. – danShumway Jul 22 '15 at 02:31
-
3I rushed to `--assume-unchanged` before reading your **update**. I undid with `--no-assume-unchanged` and _then_ did the `--skip-worktree`... Am I in the clear? – Nicolas Miari Jul 07 '16 at 05:11
-
How would I undo this, or see the list of files/patterns that currently are being ignored via `--skipworktree`, should I later change my mind and want to start tracking the file again? – Anomaly Jul 18 '19 at 15:38
-
@Anomaly see [this answer](https://stackoverflow.com/questions/42363881/how-to-list-files-ignored-with-skip-worktree). – Florian Sesser Sep 05 '19 at 16:59
Add the following lines to the [alias] section of your .gitconfig file
ignore = update-index --assume-unchanged
unignore = update-index --no-assume-unchanged
ignored = !git ls-files -v | grep "^[[:lower:]]"
Now you can use git ignore my_file
to ignore changes to the local file, and git unignore my_file
to stop ignoring the changes. git ignored
lists the ignored files.
This answer was gleaned from http://gitready.com/intermediate/2009/02/18/temporarily-ignoring-files.html.

- 18,161
- 7
- 61
- 51
-
1"!git ls-files -v | grep "^[[:lower:]]" - Any chance you know how to do this on windows cmd? – Haohmaru Mar 28 '18 at 20:20
-
11Install a real shell (for example Babun provides bash or zsh) ;) I know your feelings, but I recently switched from Windows to Linux and I'd never to use cmd again. – xeruf Jun 06 '18 at 06:50
-
You have several options:
- Leave a dirty (or uncommitted)
.gitignore
file in your working dir (or apply it automatically using topgit or some other such patch tool). - Put the excludes in your
$GIT_DIR/info/exclude
file, if this is specific to one tree. - Run
git config --global core.excludesfile ~/.gitignore
and add patterns to your~/.gitignore
. This option applies if you want to ignore certain patterns across all trees. I use this for.pyc
and.pyo
files, for example.
Also, make sure you are using patterns and not explicitly enumerating files, when applicable.

- 22,894
- 7
- 53
- 75
I think you are looking for:
git update-index --skip-worktree FILENAME
which ignore changes made local
Here's http://devblog.avdi.org/2011/05/20/keep-local-modifications-in-git-tracked-files/ more explanation about these solution!
to undo use:
git update-index --no-skip-worktree FILENAME

- 3,338
- 2
- 19
- 28
-
10There is a relevant discussion between `--skip-worktree` and `--assume-unchanged` at [this SO question](http://stackoverflow.com/questions/13630849/git-difference-between-assume-unchanged-and-skip-worktree) – Merwer Dec 09 '15 at 14:54
-
2How would I undo this, or see the list of files/patterns that currently are being ignored via `--skipworktree`, should I later change my mind and want to start tracking the file again? – Anomaly Jul 18 '19 at 15:38
-
1
-
5
-
3@Anomaly To list the files being ignored by --skip-worktree, you need this `git ls-files -v | grep ^S` – Ahmed Kareem Jun 17 '20 at 02:08
-
To exclude a whole folder, try `git update-index --assume-unchanged $(git ls-files | tr '\n' ' ')` from [this answer](https://stackoverflow.com/questions/12288212/git-update-index-assume-unchanged-on-directory/12288918#12288918) – gustavozapata Jan 27 '21 at 23:23
You can simply add a .gitignore file to your home directory, i.e. $HOME/.gitignore
or ~/.gitignore
. Then tell git to use that file with the command:
git config --global core.excludesfile ~/.gitignore
This is a normal .gitignore file which git references when deciding what to ignore. Since it's in your home directory, it applies only to you and doesn't pollute any project .gitignore files.
I've been using this approach for years with great results.
-
Thanks, @EricChen. I've updated the ansswer; give that a try and and then use `git check-ignore
` to verify. LMK if it works for you – JESii Oct 11 '17 at 14:28 -
It only worked for me without the `=`: `git config --global core.excludesfile ~/.gitignore` – E. Sundin Oct 29 '17 at 01:46
-
I put a `.gitignore` file under home directory and told git to use that file instead, then deleted the files I would like to untrack locally. However, after I push the changes, the remote repository also deleted those files. Did I do something wrong? – zyy May 12 '19 at 18:06
-
Wow, @xyz; `.gitignore` is about ignoring files that exist in your local directory. What you should have done is `git rm --cached` which removes them from the repo but leaves them in your local. You should be able to go back to your previous commit with something like `git reset --soft HEAD^` to undo that commit and recover your files. That's the beauty of git: it's all still there in your git history. – JESii May 12 '19 at 22:16
You can install some git aliases to make this process simpler. This edits the [alias]
node of your .gitconfig
file.
git config --global alias.ignore 'update-index --skip-worktree'
git config --global alias.unignore 'update-index --no-skip-worktree'
git config --global alias.ignored '!git ls-files -v | grep "^S"'
The shortcuts this installs for you are as follows:
git ignore config.xml
- git will pretend that it doesn't see any changes upon
config.xml
— preventing you from accidentally committing those changes.
- git will pretend that it doesn't see any changes upon
git unignore config.xml
- git will resume acknowledging your changes to
config.xml
— allowing you again to commit those changes.
- git will resume acknowledging your changes to
git ignored
- git will list all the files which you are "ignoring" in the manner described above.
I built these by referring to phatmann's answer — which presents an --assume-unchanged
version of the same.
The version I present uses --skip-worktree
for ignoring local changes. See Borealid's answer for a full explanation of the difference, but essentially --skip-worktree
's purpose is for developers to change files without the risk of committing their changes.
The git ignored
command presented here uses git ls-files -v
, and filters the list to show just those entries beginning with the S
tag. The S
tag denotes a file whose status is "skip worktree". For a full list of the file statuses shown by git ls-files
: see the documentation for the -t
option on git ls-files
.

- 7,437
- 5
- 35
- 54
-
3
-
Is the '!' supposed to be in `'!git ls-files -v | grep "^S"'`? The command doesn't work for me with it on there.. and seems to work fine with it removed. – Tiris Nov 03 '17 at 12:56
-
the exclamation mark in a git alias tells git to run an _external command_, rather than a _git subcommand_. I put it in because I need a shell pipeline, so I need to invoke git from outside. I just tried removing the exclamation mark (as per your recommendation), but that does _not_ work for me. I get `Expansion of alias 'ignored' failed; 'git' is not a git command`. This makes sense; without the exclamation mark: git aliases your command to `git git ls-files …`. – Birchlabs Nov 03 '17 at 13:07
-
Thanks for the explanation. I am not familiar with git alias and was just running in a shell to test before making the alias. – Tiris Nov 03 '17 at 13:41
-
This is a brilliant solution. Since git tracks per directory, when you run the above alias `git ignore
`, it only applies to that directory. And when you finally want to make your changes to that file and commit and push to remote, just use the handy `git unignore – nickang Sep 21 '18 at 02:04` to temporarily start tracking it again! Thanks! -
great but as @Tiris noted this doesn't work for all, neither for me in Windows from cmder cmd prompt. Tried without explanation mark, still doesn't work with same message: `usage: git config [
]` – obeliksz Jul 02 '19 at 08:38
This is a brief one-line solution to exclude a local file.
echo YOUR_FILE_OR_DIRECTORY >> .git/info/exclude
based on @Vanduc1102 comment. if it didn't applied run the following commend after that.
git update-index --assume-unchanged YOUR_FILE_OR_DIRECTORY

- 7,931
- 11
- 67
- 103
-
-
2You also can enter folders directly under .git/info/exclude if in case echo does not work – Umair Hamid Oct 22 '21 at 11:39
-
-
4I need to run `git update-index --assume-unchanged YOUR_FILE_OR_DIRECTORY` after the command – vanduc1102 Oct 03 '22 at 05:20
Both --assume-unchanged and --skip-worktree are NOT A CORRECT WAY to ignore files locally... Kindly check this answer and the notes in the documentation of git update-index. Files that for any reason keep changing frequently (and/or change from a clone to another) and their changes should not be committed, then these files SHOULD NOT be tracked in the first place.
However, the are two proper ways to ignore files locally (both work with untracked files). Either to put files names in .git/info/exclude file which is the local alternative of .gitignore but specific to the current clone. Or to use a global .gitignore (which should be properly used only for common auxiliary files e.g. pyz, pycache, etc) and the file will be ignored in any git repo in your machine.
To make the above as kind of automated (adding to exclude or global .gitignore), you can use the following commands (add to your bash-profile):
- Per clone local exclude (Note that you should be in the root of the
repository when calling the command because of using the relative path), change ##FILE-NAME## to
.git/info/exclude
- Global .gitignore, first make global .gitignore here then
change ##FILE-NAME## to
~/.gitignore
Linux
alias git-ignore='echo $1 >> ##FILE-NAME##'
alias git-show-ignored='cat ##FILE-NAME##'
git-unignore(){
GITFILETOUNIGNORE=${1//\//\\\/}
sed -i "/$GITFILETOUNIGNORE/d" ##FILE-NAME##
unset GITFILETOUNIGNORE
}
MacOS (you need the .bak for sed
inplace modifications (i.e. you are forced to add a file extension to inplace sed. i.e. make a backup before replacing something), therefore to delete the .bak file I added rm filename.bak)
alias git-ignore='echo $1 >> ##FILE-NAME##'
alias git-show-ignored='cat ##FILE-NAME##'
git-unignore(){
GITFILETOUNIGNORE=${1//\//\\\/}
sed -i.bak "/$GITFILETOUNIGNORE/d" ##FILE-NAME##
rm ##FILE-NAME##.bak
unset GITFILETOUNIGNORE
}
Then you can do:
git-ignore example_file.txt
git-unignore example_file.txt

- 351
- 1
- 4
- 6
In order to ignore untracked files especially if they are located in (a few) folders that are not tracked, a simple solution is to add a .gitignore
file to every untracked folder and enter in a single line containing *
followed by a new line. It's a really simple and straightforward solution if the untracked files are in a few folders. For me, all files were coming from a single untracked folder vendor
and the above just worked.

- 158
- 1
- 10
-
2Great! FYI: This works only because git only tracks (and lets you commit) files, not folders. – jmiserez Feb 28 '20 at 16:14
Just Simply add path to the file ypu want to remove from commits on any branch of current repo:
- Unhide hidden files in Windows Directories Settings
- Open Path REPO_MAIN_PATH/.git/info/exclude
- Add for example **/toExcludeFile.bat
And thats it ! For me answears above are too long. KISS - Keep it stupid simple

- 260
- 1
- 4
- 9
-
Your solution would be more simple if you didn't explain how it's the most simple. – AlexanderGriffin May 31 '22 at 17:11
For anyone who wants to ignore files locally in a submodule:
Edit my-parent-repo/.git/modules/my-submodule/info/exclude
with the same format as a .gitignore
file.

- 2,061
- 24
- 17
TL;DR - filter the output to ignore the files
Don't do it. There are excellent answers on the technical ways to do this. However, I have found this Q/A page several times. As you can see there are multiple solutions. The problem is that each will make git ignore the file; which might be what you want now, but maybe not in the future.
The devil in the details are,
git
will no longer report the files.- You need to remember which of the mechanisms you used.
Either add it to .gitignore or write a filter to git status
that will actively filter out the text. Each will ignore the file, but the answer of why it is being ignored is more obvious. The 2nd case of a wrapper script (or command line recall) makes it abundantly apparent what you are choosing to ignore and that your workflow is non-standard.

- 21,212
- 6
- 68
- 105
If your repo doesn't already have a .gitignore file, then a simple solution is to create a .gitignore file, and in it add .gitignore
to the list of files to be ignored.

- 1,216
- 1
- 13
- 34
-
6And what if the team then wants to add to add a gitignore later? Does this even work? Sounds like a terrible idea and like something that shouldn't even work. – Bjorn Aug 09 '16 at 01:58
-
This guy's answer cracked me up. No way anybody's doing this. – Martyn Chamberlin Jun 20 '17 at 20:17
-
This is a quick and simple solution, as long as there is a place to put it. Our repo has a shared `.gitignore` file at the top. But my dirty files are in a deep folder, so I just added my own `.gitignore` next to them. +1 – joeytwiddle Oct 07 '19 at 04:03