Is it possible to have a file that is part of the Git repo and created locally (with git clone
) but where the contents are not tracked?
Here's my example. I have the file MyFolder\DummyFile.txt
with contents:
This file will not be tracked by Git when its contents change.
The file is added to the Git repo:
$ cd MyFolder
$ git add DummyFile.txt
$ git commit -m "Dummy file"
$ git push
A .gitignore
is created in MyFolder
with the line:
DummyFile.txt
What I expected is that the contents of DummyFile.txt
could be freely modified without being notified of changes with git status
. But whenever I change the file, Git reports it is modified
and needs to be staged.
Note: I still want the file to be created locally on git clone
or git pull
(if it doesn't exist locally), but once it exists, I'd like Git to forget about it.
Update 1
Comments suggested looking at this question recommending assume-unchanged, and a later comment suggested this question recommending skip-worktree.
Have now tested both in a local Windows Git repo and then in the same repo inside an Ubuntu VM. I am able to confirm that both of the following commands do what I need:
git update-index --assume-unchanged path/DummyFile.txt
git update-index --skip-worktree path/DummyFile.txt
skip-worktree
is to be preferred because it has a meaning closer to my intention which is "Git shouldn't track changes to this file, but developers can and are encouraged to make changes to the file".
Note: You must run the command on each instance of the Git repo! When the repo is cloned, the file will be tracked again. The questions mentioned above were not clear on this point.
Update 2
From the comment by @1615903, another question suggests the following elegant solution. The repo has a default file called DummyFile.Default.txt
. The developer should rename this to DummyFile.txt
locally, and DummyFile.txt
is in the .gitignore
.
For anyone who comes here, there are two better solutions to assume-unchanged
which are closer to the meaning I intended.