I have a tmp directory in my git repo I'd like to still exist, but be ignored. I added it to .gitignore
, but git status
still tells me about changes to files in that directory. I tried git rm -r --cached
, but that removes it from the remote repo. How can I stop tracking changes to this directory, but still allow it to exist? I also need to do this for 1 file, but changes to that also show up in git status
after .gitignore
ing them. What should I do?

- 1,121
- 2
- 8
- 3
-
1please write down what exactly does your .gitignore file look like? – kdehairy Jul 25 '12 at 06:25
5 Answers
Instead of .gitignore
, you can update local git repository by running following command:
git update-index --assume-unchanged <file>
In this case a file is being tracked in the origin repo. You can modify it in your local repo and git will never mark it as changed. Read more at:
- http://blog.pagebakers.nl/2009/01/29/git-ignoring-changes-in-tracked-files/ - was reported dead at some time (sorry, not mine)
- http://archive.robwilkerson.org/2010/03/02/git-tip-ignore-changes-to-tracked-files/ - another one covering the same topic

- 25,621
- 41
- 157
- 256
-
25
-
3
-
4
-
I'm using git version 1.8.1.2 and I `git add` has no effect, to no push available. But you can revert this. – ducin Sep 03 '13 at 12:02
-
2hmm i would rather mark a file as "it is not a git file, never sync it with git, even in someones other repo" – Fantastory Dec 05 '13 at 15:06
-
14You can revert it with `git update-index --no-assume-unchanged
`. If you want to list them `git ls-files -v | grep '^h'`. – Sanghyun Lee Aug 20 '14 at 23:27 -
1This has no effect on my local repo. It says "Ignoring path xyz/" but on git status, still shows that path in the modified list. – Tyguy7 Apr 01 '15 at 21:28
-
1@Tyguy7 you have to `update-index` *before* you make `git add`. If you added something ("changes to be committed") then update-index will apply from this moment on. Order is important. – ducin Apr 02 '15 at 08:58
-
@stkent you are right :) Well, that's not my fault :) I updated the description. – ducin May 27 '16 at 21:50
-
-
@Tyguy7 - it can only be done to individually files. I don't know of a way to do it recursively.. – blizzrdof77 Apr 19 '19 at 01:55
-
Now we can push the placeholder credential/config files to the remote, without deleting them. it should be the accepted answer!!! – mochadwi Jun 01 '19 at 23:25
-
They say `--skip-worktree` is better than `--assume-unchanged` for this purpose - https://stackoverflow.com/a/20241145/345648 ; https://stackoverflow.com/a/13631525/345648 – Alexander Taylor Feb 10 '23 at 21:25
Ignoring changes made to files while allowing them to exist is the exact purpose of .gitignore
. So adding the files (or directories) to .gitignore
is the only thing you have to do.
But your problem is that git is already tracking the files you want to ignore and .gitignore
doesn't apply to tracked files. The only way to stop this tracking is to tell git to remove them. By using git rm --cached
, you prevent git from deleting your local files, but any other repository getting your changes will apply the removal. I don't think there's a way to avoid that from your own repository. You must do something on the other repositories, or accept the files will be removed.
To prevent the removal on each other repository you can:
- (obviously) backup the files somewhere, pull the changes and restore the files,
- or also
git rm --cached
the files and commit before pulling your changes. Git will nicely merge the two removals without touching the already untracked files.

- 7,525
- 40
- 44
-
7That doesn't have to be true ("stop tracking = remove file"). You can still have a file tracked in a repo and not to see any changes made, using: `git update-index --assume-unchanged
`. Take a look at: http://blog.pagebakers.nl/2009/01/29/git-ignoring-changes-in-tracked-files/ – ducin May 08 '13 at 13:30 -
this solved my problem because I need to remove file from pushed repositorie in git so ```git rm --cached
-r ``` and after this push changes to repositorie again so the file is removed – Vinicius Cardoso Feb 22 '20 at 15:49
Put a /
at the end of the directory name in your .gitignore
file, i.e.
tmp/
If have tracked files inside that directory, you need to tell git to forget about them first (before you add the dir to the ignore list). Assuming you have nothing vital in there (i.e. that you can scratch it):
git rm -rf ./tmp/
git commit -m "untrack tmp dir"
mkdir tmp
echo tmp/ >> .gitignore
git add .gitignore ; git commit -m "add tmp/ to ignore list"
New files in that directory will not be tracked.
The --cached
option to git rm
only works on the index (pending changes more or less). It has no effect on the working tree or the status of what has been tracked or not.

- 202,337
- 40
- 393
- 406
-
-
Hey Mat, if I have something like /Media in different folders that I'd like to ignore, is that possible? So like /1/Media, /2/Media, all the way up to like 99? – Nic Jun 11 '11 at 17:22
.gitignore has no effect on tracked files.
What you want is to set the assume-unchanged bit on the files in the tmp/ directory. There's a good explanation how to do that here: Git: untrack a file in local repo only and keep it in the remote repo
Also, one-liners for setting assume-unchanged on all files in a directory - git update-index --assume-unchanged on directory .

- 1
- 1

- 16,281
- 5
- 47
- 60
It sounds like you are trying to track a file (e.g. index.php
), add it to a remote repository, then stop watching tracking it, while keeping the file in the remote (i.e. keep index.php
unchanged on the remote repo while changing it locally).
From what I understand, git cannot do this. You can either track a file, or not. If you track a file, it exists in the remote repo, and changes when you commit changes to it. If you don't track a file, it doesn't exist in the remote repo.
Because it is not possible to do exactly what you want with git, there are potentially other solutions, depending on your exact situation. For example, why do you not want index.php
to change on remote when you change it locally? Are there user-specific settings in the file? If this is the case, you can do:
cp index.php index_template.php
git rm --cached index.php
Now edit index_template.php to be as you want it to appear on the remote repo. Add something to your README to tell the people using your repository that once they clone it, they must copy index_template.php to index.php and edit it to suit their needs.
git add index_template.php
git add README
git commit -m 'added template index.php file'
git push
When someone clones your repo, they must create their own index.php
. You've made it easy for them: simply copy index_template.php
to index.php
and revise it with computer-specific settings.

- 2,317
- 2
- 28
- 40