Home / Comment permalink

Using GitHub with Acquia Cloud

Most Drupal developers are moving towards Git, and many of them prefer to host their Git repos at GitHub for their excellent Git support, Pull Requests with integrated code review, and more. At Acquia, we think GitHub is terrific, too, and like to use it for many of our own public and private projects.

Many people have asked us whether it is possible to keep their site’s code in GitHub and still host it on Acquia Cloud. The answer is yes, and it’s pretty simple, too. The trick is to have two "remotes" for your local repo clone, one at GitHub and one at Acquia Cloud.

Suppose you have an existing repo at GitHub containing your site’s code. You make a local clone like this:

$ git clone git@github.com:me/mysite.git
$ cd mysite
$ git remote -v
origin    git@github.com:me/mysite.git (fetch)
origin    git@github.com:me/mysite.git (push)

GitHub is the "origin" remote, the default location for "git push" and "git pull". Now, you’d like to deploy this site to Acquia Cloud. You simply add your Acquia Cloud repo as an additional remote named something short, like "ac", and then do an initial "git push --force ac" to re-initialize the Cloud repo:

$ git remote add ac mysite@svn-18.devcloud.hosting.acquia.com:mysite.git
$ git remote -v
origin    git@github.com:me/mysite.git (fetch)
origin    git@github.com:me/mysite.git (push)
ac    mysite@svn-18.devcloud.hosting.acquia.com:mysite.git (fetch)
ac    mysite@svn-18.devcloud.hosting.acquia.com:mysite.git (push)
$ git push --force ac

Now you have two remotes, origin (GitHub) and ac (Acquia Cloud). You can edit some files and push them to GitHub:

$ vi somefile.php
$ git add somefile.php
$ git commit -m ‘edited somefile.php’
$ git push origin master

You can also push the same changes to Acquia Cloud:

$ git push ac master

Your new code is now in both your GitHub and Acquia Cloud repo, and is running on your Acquia Cloud site.

Suppose that now you deploy your code on Acquia Cloud from the Development environment (running the master branch) to Production. This creates a new "release tag" in your Acquia Cloud repo showing you exactly what code you released that day. You do not have to synchronize that release tag to GitHub, but you can:

$ git pull ac
From svn-18.devcloud.hosting.acquia.com:mysite
* [new tag]         2012-03-12 -> 2012-03-12
$ git push --tags

Now your GitHub repository contains the same release tag as your Acquia Cloud repo.

There is one other wrinkle you may need to address. Acquia Cloud requires that you keep all of your Drupal site code in the directory "docroot" in your repo. Your existing GitHub repo may not be set up that way, and you may have a lot of commit history in that repo that you want to preserve. No worries; you can use "git subtree" to translate your GitHub repo’s root directory into an Acquia Cloud "docroot" directory. That’s a subject for another blog post, but luckily Acquia’s Peter Wolanin has already written it; see Using git subtree to Make a Distro Your Docroot.

Try a free 30-day trial of Acquia Dev Cloud today!


Posted on by Tyler (not verified).

Please let this be the first-fruits the slow migration of Drupal to GitHub :)

Posted on by Jerad Bitner.

Sure you could add a secondary remote, but is there a way to automate it so you don't have to worry about keeping these in sync?

We currently have a Jenkins job setup that detects changes to GitHub and force pushes those into Acquia. This works really quite well, and makes so that no one has to worry about an extra step.

However, after the lifetime of a project, we're then stuck with the dilema of maintaining this for the client, which is not ideal.

So what would be ideal is if Acquia had a way to automate this right away so that any push to the GitHub repository would automatically be reflected on the Acquia environment.

Posted on by si@technocrat.com.au.

Yeah this would be so great. So great.

Posted on by Dominic DiCicco.

What about multiple cloud instances all being pushed to from the same github/bitbucket repo? The settings.php file needs to be distinct per environment. What is your recommendation on being able to keep that separate per cloud instance but having a single origin of code in github?

Posted on by Suchi Garg.

I have the same query. How is the settings.php and DB connections managed?

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

Filtered HTML

  • Use [acphone_sales], [acphone_sales_text], [acphone_support], [acphone_international], [acphone_devcloud], [acphone_extra1] and [acphone_extra2] as placeholders for Acquia phone numbers. Add class "acquia-phones-link" to wrapper element to make number a link.
  • To post pieces of code, surround them with <code>...</code> tags. For PHP code, you can use <?php ... ?>, which will also colour it based on syntax.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <h4> <h5> <h2> <img>
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.