Git Subtree: An Easier Way to Import a Repository into Dev Cloud

Russell Keppner's picture
Tue, 04/24/2012 - 10:00am -- Russell Keppner

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.

Initial Setup

  1. Log in at and select one of your “subscriptions,” under Dev Cloud.
  2. Click New site, and add the site you’re going to import.
  3. Switch to the subscription for your newly added site.
  4. Click Users and keys, and add your SSH public key.
  5. Click Workflow, and copy the “Git URL.”
  6. 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://
cd git-subtree
sudo bash

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[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 Databases link 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).


Russell Keppner's picture
Submitted by Russell Keppner on

Yes, I'd say things are working as expected. The beginning (9 months ago) was a little bumpy. Sometimes there was a disconnect between Acquia sales and how things actually worked, but we eventually figured everything out.

Before we standardized on Dev Cloud, we auditioned a few other options (like Pantheon), and for what we're doing, Dev Cloud made the most sense. We have a number of different clients on a single Pro instance, and we really like being able to get out of the Linux sysadmin game. Our goal is to outsource everything but our core competencies.

Yes, it's work to move sites over to Acquia, especially if you already have existing code repositories. But we got things set up in our Drush aliases (see my other post) so that we could easily push databases and uploaded files to the Dev Cloud environments.

By "40 sites" and "1 core" do you mean that you're hosting a multi-site setup? Or do you just have 40 different installs?

Russell Keppner's picture
Submitted by Russell Keppner on

No, Acquia doesn't do code updates for core or contributed modules (or anything else), at least not with a Dev Cloud subscription. You'll have to do the updates yourself and promote them via Git (or Subversion). So you may still want to stay on a multi-site Drupal setup. You'll just need to create 40 different databases through the Acquia Network web interface.

No, we haven't actually spent any time setting up Solr with Acquia Dev Cloud. Sorry.