Configuring Drupal Multisites as Git Submodules
After thinking about the set up in my previous post, I decided that I wanted a good way to push changes from the dev to the production site. So, I found Simon Hamner’s post on using submodules for this and made some modifications. I also got the whole setup working with 3 sites, dev.my-project.local, my-project.local and www.my-project.com.
First, I set my server with a folder called git which will hold the bare repository for my application in git/drupal and the repository for my sites called git/sites:
$ mkdir git
$ cd git
$ cd sites
$ git init
I added settings.php to a .gitignore file and checked the whole thing in to master, because I don’t ever want my sites folders to track the settings for a given location. Then, I moved up the sites code I developed earlier and checked it into a dev and production branch in git/sites. I created the bare repository for git/drupal now too.
Then, I went back to my local machine and removed the sites I had developed. I added them in as submodules instead:
$ git submodule add ssh://<snip>/git/sites sites/dev.my-project.local
$ git submodule add ssh://<snip>/git/sites sites/my-project.local
$ git submodule init
I made sure that each site was tracking the right branch and then checked the changes into the application branch of my project. Next, I added the remote repository:
$ git remote add origin ssh://<snip>/git/drupal
$ git push origin master
$ git push origin modules-and-themes
$ git push origin application
Now, I’m ready to clone this onto my host machine
$ git clone -l git/drupal/ production
$ cd production
$ git fetch
$ git checkout -b modules-and-themes
$ git rebase origin/modules-and-themes
$ git checkout -b application
$ git rebase origin/application
and check in its application
$ git submodule add ssh://<snip>/git/sites sites/www.my-project.com
$ git submodule init
I pushed this up and pulled it down to my local machine, so now both repositories know all about my three sites. I will only serve the two local sites locally and the www.my-project.com from my host, but I can live with that. I like that I can work on the two branches (dev and production) on the various sites, merge changes and commit the results as submodules into the application branch of my Drupal site.

Discussion Area - Leave a Comment