Search code examples
gitgitignore

How can I store a file in GIT in such a way that it will not be tracked?


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?


Solution

  • 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.