In my last post about moving an existing Drupal Git repository into Acquia Dev Cloud without losing history, the best way I could put together to actually merge in the Git repository was to use a rather obtuse (if effective)
git filter-branch command. Thankfully, Barry Jaspan, the project owner of Dev Cloud, was kind enough to point out that there was an easier way. In fact, Peter Wolanin, another Acquia engineer, has already documented it on the Acquia blog.
For the sake of clarity and completeness, I’m going to summarize that method here. Most of this content is a repeat of my former post, though thankfully shorter because of the
git subtree command. If any of the information below seems out of context, you may want to check the last post for more detail.
- Log in at network.acquia.com and select one of your “subscriptions,” under Dev Cloud.
- Click New site, and add the site you’re going to import.
- Switch to the subscription for your newly added site.
- Click Users and keys, and add your SSH public key.
- Click Workflow, and copy the “Git URL.”
- Use the Git URL to clone the repository to your local system.
The initial repository from Acquia contains a series of directories that serve as placeholders. Unlike a standard Drupal installation, the core Drupal files need to go in the docroot subdirectory. This directory initially has a couple of default files that we don’t need, so we’ll delete them.
cd [site-dir] git checkout master git rm -r docroot git commit -m "Removed default docroot." git push -u origin master
Importing the Existing Codebase
Before we go any further, you’re going to need the git-subtree command. If, like me, you’re working on OS X and have Homebrew installed (and I highly recommend you do), you can just do:
brew install git-subtree
Otherwise, you can get it directly from GitHub with:
git clone git://github.com/apenwarr/git-subtree.git cd git-subtree sudo bash install.sh
Once that’s done, all we have to do is use git-subtree to pull our existing Drupal repository into the Dev Cloud repo.
git subtree add --prefix=docroot [email protected]:[user]/[project].git master
In this instance, we’re pulling directly from our Bitbucket repository, but the same method will work for GitHub or your own homegrown setup. In fact you can just use the directory of your current repo as the Git URL, if it’s already local.
The Dev Cloud repo comes with its own .gitignore file in the top directory, so we don’t need or want the one that came with Drupal, and which is likely still in place.
git rm docroot/.gitignore
One of the reasons for this is that we need to include the settings.php file in the repository for Dev Cloud, since Acquia has their own way of defining a database connection for each environment (dev, test, and prod). If you click on the Databaseslink under Dev Cloud, you’ll see a “require statement” that you need to add to the bottom of your settings.php file, so go ahead and add it now. (If for whatever reason you don’t already have a settings.php file, just do a
cp docroot/sites/default/default.settings.php docroot/sites/default/settings.php first.)
git add docroot/sites/default/settings.php git commit -m "Import of existing repository." git push -u origin master
That’s all there is to it—much, much easier than my former method. Thanks again to Barry Jaspan and Peter Wolanin at Acquia for introducing me to this method. Hopefully this information eventually makes it into the Dev Cloud docs for importing Git codebases (hint, hint).