I have an .ini
file in my git repository. It is meant to be a default configuration file documenting possible keys for the user to set. I would like that a user cloning the repository get these defaults. However, later on, each of the users (developers) would modify the .ini
according to their preferences. The repository also has a .gitignore
file where the .ini
is listed. The problem is that I don't know how to tell git not to track this file. What would be the right way to achieve this?
Asked
Active
Viewed 226 times
2

Leandro Caniglia
- 14,495
- 4
- 29
- 51
-
6You can have something like a git-tracked `config.ini.tmpl` that holds the default config. The user could either copy it to `config.ini` themselves, or generate the latter by a git-tracked shell script if necessary. The copied/generated `config.ini` should be git-ignored. – terrorrussia-keeps-killing Apr 03 '21 at 01:32
-
I re-read you post few times and still not able to get my head around it. You want your `.ini` to be downloaded with clone but not tracked by git when developers modify it and try to push. You also said that you already have the `.ini` mentioned in your `.gitignore`. That should fulfil your requirement. Where's the problem then? Am I missing onto anything here? – Asif Kamran Malick Apr 03 '21 at 04:28
-
1https://stackoverflow.com/search?q=%5Bgit%5D+ignore+changes+tracked+file – phd Apr 03 '21 at 09:58
1 Answers
2
You could have users run git update-index --skip-worktree my.ini
, probably as part of a setup script. They can undo this with --no-skip-worktree
later, if they mean to push changes back.
However, using a template as per @fluffy's comment is usually a better call. You could still have a setup script to make sure the template is instantiated.
As you've probably noticed already, .gitignore
doesn't stop already-tracked files from being, well, tracked.

usretc
- 723
- 4
- 9