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
- Create a new site directory
git init
to initialise a blank local git repo - Link this with the remote framework repo
git remote add origin git@github.com:username/framework_repo
- Pull a fresh copy of the remote framework
git pull origin master
- Make changes to site files and commit them back to the remote repo
git push origin master
- Pull these changes down to the other sites
- 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.
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.create dummy files like
config.default.php
and copy them after the first pull to the ignored name.done with the first to steps!
config.php
to your.gitignore
.config.php-dist
post-receive
, like below.git pull
, but the copy will only be done whenconfig.php
does not exist.post-receive
example (tailor to your needs):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.