0

tl;dr: How to commit a file (with default content) to a git repository once and then force git to never track its changes for any user? What is the dumb-man-checklist for achieving this?


How to achieve both of these conditions in the same time in git / GitHub:

  1. The file must be in remote repository (git clone must get it) otherwise the app won't start
  2. Once cloned locally, no changes to the file must be tracked; ever and for everyone

Just like that:

  • git clone → anyone have the file; app works on default configuration
  • Some developer changes config to match its own expectations
  • Repository is never polluted with local changes

Is it possible out-of-the-box, i.e. without every developer doing git update-index --assume-unchanged <file> dozens of times after git clone?

If yes, then what are the exact steps (from the repo owner / creator of the file perspective) to achieve this?

I've spent last two hours on trying to achieve this. But I must be doing something wrong or I don't understand something, because each attempt has failed.

So far I have tried:

  1. --assume-unchanged and --skip-worktree: here, here, here, here, here or here (local changes still tracked)
  2. git rm --cached <file>: here, here, here or here (file is removed from repo; not an option here)
  3. Add file to .gitignore and commit this file (does not work for the file already in repo)

Also solutions with two files (the default one and the local one -- here and here) are out of the question for the scenario I am talking about.

I understand that this is a duplicate, but I worked really hard last couple of hours and can't find some definitive step-by-step list for keeping files (with default content) in repo while avoiding polluting it with any local changes done by anyone.

trejder
  • 17,148
  • 27
  • 124
  • 216
  • 7
    You don't. Keep a *template* under source control, and use an untracked copy of the template for actual configuration. – chepner Jul 24 '23 at 17:46
  • 2
    Or have CI/CD reject commits that modify that file. – Jim Redmond Jul 24 '23 at 18:39
  • 2
    @JimRedmond or both. These solve different problems. The template makes it so no one accidentally commits the actual file. Your idea makes it so no one purposely commits the actual file. – TTT Jul 24 '23 at 20:27
  • 2
    True. A pre-commit hook (using a tool like https://pre-commit.com/) could also help avoid commits, intentional or otherwise, but it'd have to be set up on everyone's systems. – Jim Redmond Jul 24 '23 at 20:46
  • Thank you for all your thoughts. All of your comments sounds like a great answer to this question. Anyone care to write one, so I can accept it and bring some rep to someone? – trejder Jul 25 '23 at 19:30

0 Answers0