Reputation: 319
I've found numerous topics regarding this, but none that solve the specific problem I'm looking to solve.
I have a configuration file called local.properties in the root directory of my repo. Each developer using the repo will have different values in this configuration file. I would like to have a default file in the repo, such that if a developer clones the repo (or pulls and doesn't have that file, if possible), it will be added, but I don't want to track changes locally (ie. when they make their changes to the file, git should not track it as a modified file). I don't want the developer to have to do any extra git commands to get this working (eg. git update-index --skip-worktree local.properties
), and ideally, I'd like this situation to remain the same even when the repo is forked.
Working from comments on this post, I tried
git rm --cached local.properties
, committing, adding the file to .gitignore
, then committing and pushing, but this causes the upstream file to be deleted..gitignore
, create the template file, force add it with git add -f local.properties
, commit and push it, but changes are still being tracked (and using git rm --cached local.properties
leaves me in the same position as before)And at least a few other variations on doing these in different orders and with pushes, etc. and I cannot get the file to actually stay in the repository, untracked, with local changes not triggering modifications in the staging area. Is this possible?
Upvotes: 2
Views: 308
Reputation: 1
As detailed in this article, use:
git update-index --skip-worktree local.properties
This will tell git that the local.properties file is always up to date, and will ignore local changes to it. If you need to make later amendments to the file, you will need to re-run the command to untoggle the "always updated" status, modify and commit/push it, and then run the command again to re-toggle the status.
Upvotes: -1
Reputation: 30398
Commit and track the template under a different name (say, local.properties.template
) and have your devs copy it to the actual name when they first clone the repo. You can even include a setup script in your repo to do that copying for them.
Upvotes: 1