2

I have several config files that I would like to keep on GitHub but ignore further changes. By ignoring further changes I mean "If anyone clones the repo they will get the default version of those files and can edit those locally but when run git status those files will not appear."

So what I did/try so far is:

  1. I add those files and make initial commit/push to GitHub.
  2. Later add those files to .gitignore and commit again to GitHub. But then when someone clone that repo, those files remain tracked.

So then I tried two options:

  1. git rm --cached .
    git add .
    git commit .....`  
    

But in this case a later commit actually deleted those files.

  1. Tried git update-index --assume-unchanged [filepath] and it works but I don't want someone clone the repo and then to run this command. Is there any way without this command I can achieve my goal?
random
  • 9,774
  • 10
  • 66
  • 83
Rashidul Islam
  • 1,623
  • 3
  • 18
  • 24
  • possible duplicate of [Git collaboration - how to manage configuration files](http://stackoverflow.com/questions/4743770/git-collaboration-how-to-manage-configuration-files) – ChrisGPT was on strike Apr 02 '15 at 11:34

1 Answers1

1

In summary:

I see this is not possible as it violates the constitution of git. There are some workarounds though.

  1. Manage default settings as distraibution copy which store in remote repo and under version control, for example config.php-dist(config.php.dist) for distribution and add config.php to .gitignore and later after cloning from remote repo, rename that file to something like config.php and adjust the settings locally. As config.php added to .gitignore so local settings copy never shows up in git status list.
  2. OR maintain .env files for managing different settings for different environment, read those data from config.php file based on environment, Something like this: https://github.com/laravel/laravel.
Rashidul Islam
  • 1,623
  • 3
  • 18
  • 24