3

I have a database.php. I want to keep it in my github repository without any sensitive information.

First I pushed to my repository without any sensitive info.

Now I added my database info so that I can use it locally.

I added to .gitignore. And I did rm --cached database.php. But it deleted the database.php from my github repository after a push.

How can I keep different content in my local and github repository?

Thanks in advance.

shin
  • 31,901
  • 69
  • 184
  • 271

2 Answers2

3

You should make 2 different files one actual database.php and one database.php.example or something like that and then add database.php to .gitignore

DipSwitch
  • 5,470
  • 2
  • 20
  • 24
  • +1: The answer is often to avoid the problem! In these situations, with data files containing sensitive information, essentially *every* developer and user will end up putting sensitive information in there. The developers won't want to commit those changes, and the users won't want them to be overwritten if they update, so it's definitely good to have the template in a separate file. – Cascabel May 17 '11 at 14:57
  • 1
    Another suggestion is to make your app handle the missing file gracefully by generating a default one. This way a new developer doesn't have to go in and copy the example file over, things just work out of the box. If they already have the file, it's not overwritten. – Tekkub May 17 '11 at 22:58
  • 1
    That is also a nice technique but the problem with that is that you make it easy to use default configurations which most of the time means you make it easier for someone to make mistakes or setup a vulnerable website :) – DipSwitch May 20 '11 at 09:39
1

You should use a filter driver able to:

filter driver

  • on checkout, in the smudge script, detect the content (those 'filter driver' scripts don't have the name of the files they are filtering) of a database.template
  • generate the private, always ignored, database.php, based on the values of a:
    • database.private.value file (also always ignored)
    • or, if database.private.value isn't found (which is the case for your user cloning your repo), a database.public.value file (which is pushed to the remote repo)
  • no need to do anything on the commit (script clean) step.
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250