1

I am developing an application in Code Igniter with a friend. Because both of us have different database logins on our machines, we have different "config/database.php" files.

How can I tell Git that both of us have different database configurations? Right now, we are getting merge conflicts every time we pull because "config/database.php" differs for us.

Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
dangerChihuahua007
  • 20,299
  • 35
  • 117
  • 206
  • How are you maintaining sessions? Does your application access a SOA? Or does each client hold it's own db connection? If so, you can just use a common login for the service and implement a user login interface and a simple authentication mechanism. – Jason Huntley Mar 14 '12 at 19:35

4 Answers4

7

I usually rename the /application/config/database.php file to /application/config/database.default.php (versioned) and add the original path to the .gitignore file. Then, each developer copies the default (unversioned file) back to the original path and edits per their local settings.

This becomes an extra step in the server setup process, but it saves the grief you mention.

landons
  • 9,502
  • 3
  • 33
  • 46
1

Two options are:

  1. Don't version control this file anymore (I leave git-command to your research)
  2. Use the .gitignore file

As result you'll have file on old place, butit will not interfere with "another" file anymore

Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
Lazy Badger
  • 94,711
  • 9
  • 78
  • 110
1

We usually put database configuration files in the .gitignore file to avoid these issues. It's a good idea anyway not to put these config files with their user/passwords in git.
We'll frequently keep a config/database.yml.template file (we're using rails) as the basis for folks to copy to config/database.yml and then edit to their local machine. The database.yml filename is put in the .gitignore file (which is shared under version control).

Basics on gitignore can be seen here.
Additional info, including pitfalls to avoid at: Ignore files that have already been committed to a Git repository

Community
  • 1
  • 1
Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
1

Have a single file that selects config based on an environmental variable. Set that variable in your server's config.

<?php

if (getenv('WHOS_CONFIG') == 'mine') { … } else { … }

and in server config (which you wouldn't verison, otherwise same problem arises again :)
e.g. for Apache:

<VirtualHost *>
SetEnv WHOS_CONFIG mine
…

Alternatively, have a common database.php config file that includes database.local.php file that is not versioned. The latter would override variables you need.

Kornel
  • 97,764
  • 37
  • 219
  • 309