Rashidul Islam
Rashidul Islam

Reputation: 1702

Keep file on remote, but cloning repo via Git will ignore that specific file

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?

Upvotes: 2

Views: 954

Answers (1)

Rashidul Islam
Rashidul Islam

Reputation: 1702

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.

Upvotes: 1

Related Questions