tags:

views:

32

answers:

3

I'm using git to manage an extended CodeIgniter Framework. It's a clone of the current CI release with extra helpers, libraries ect.

I have many sites all using this framework and if I add a new helper method or fix a bug in one site I want to be able to easily update all the other sites without overwriting any of their custom files.

I wish to achieve the following workflow

  1. Create a new site directory git init to initialise a blank local git repo
  2. Link this with the remote framework repo git remote add origin [email protected]:username/framework_repo
  3. Pull a fresh copy of the remote framework git pull origin master
  4. Make changes to site files and commit them back to the remote repo git push origin master
  5. Pull these changes down to the other sites
  6. Repeat steps 4 & 5

Thats all fine, BUT:

  • Files like config.php and database.php should never be committed back to the remote repo as they are unique to each site.
  • However I want them to exist in the remote repo so on the first pull request the default files are downloaded to my local directory.
  • Further more if I do another pull from the remote repo to update the framework I do not want these files to be overwritten

Whats the best way to achieve this? Some .gitignore voodoo? I already use .gitignore to ignore files, but in this case its slightly different as I want to pull the file only on the first request.

I hope that makes sense.

+3  A: 
  • Files like config.php and database.php should never be committed back to the remote repo as they are unique to each site.

Put all the files that shouldn't be in the repo to the .gitignore file. That is hardly any vodoo, it's just a list of files that should be ignored.

  • However I want them to exist in the remote repo so on the first pull request the default files are downloaded to my local directory.

create dummy files like config.default.php and copy them after the first pull to the ignored name.

  • Further more if I do another pull from the remote repo to update the framework I do not want these files to be overwritten

done with the first to steps!

jigfox
Thanks, that's a really elegant and simple solution.
th3hamburgler
A: 

I think what you want is a number of branches for each customised site and an extra upstream branch for the common files. It doesn't really make much difference where each branch lives (or if you've got multiple copies of it).

When you make a change to the common files, you can either make it directly on the common branch or create a checkin on one of the customised branches then cherry-pick it onto the common branch. You don't want to push changes to the common branch, because that will take the customisations as well as the fixes. It's safe to pull from the common branch to the customised branches, as any changes you've made will be merged in.

Andrew Aylett
+1  A: 
  1. Add config.php to your .gitignore.
  2. Create the default/distribution/base configuration to use, config.php-dist
  3. Create a Git hook, post-receive, like below.
  4. The hook will execute after each git pull, but the copy will only be done when config.php does not exist.

post-receive example (tailor to your needs):

#!/bin/bash
[ -f 'config.php' ] || cp config.php-dist config.php
janmoesen
there missing steps, see [Can Git hook scripts be managed along with the repository?](http://stackoverflow.com/questions/427207/can-git-hook-scripts-be-managed-along-with-the-repository)
jigfox
@Jens: true, I forgot about that. We actually use an init script when first cloning our repository which takes care of that.
janmoesen