2

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

  • pushing the template file upstream, calling git rm --cached local.properties, committing, adding the file to .gitignore, then committing and pushing, but this causes the upstream file to be deleted.
  • add the file to .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?

EaterOfFromage
  • 301
  • 4
  • 11
  • 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. – spectras Jul 25 '18 at 21:12
  • @spectras that... is actually not a terrible idea. Simple, but effective, not sure how that didn't occur to me before. I'm still curious though if this is a functionality available with git, it seems like templating local configurations would be a pretty standard use case. – EaterOfFromage Jul 25 '18 at 21:15
  • @EaterOfFromage Git does not have any built-in functionality to copy a file when the repo is fetched. For security reasons, it also does not support automatically running a script from the repo after the repo is fetched. – Rory O'Kane Jul 25 '18 at 21:45
  • @RoryO'Kane Sorry, I wasn't clear, I meant I was wondering whether the functionality I described in my **initial post** was available. – EaterOfFromage Jul 26 '18 at 13:42

1 Answers1

1

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.

Rory O'Kane
  • 27,337
  • 11
  • 91
  • 127