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 firstname.lastname@example.org:me/mysite.git $ cd mysite $ git remote -v origin email@example.com:me/mysite.git (fetch) origin firstname.lastname@example.org: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 email@example.com:mysite.git $ git remote -v origin firstname.lastname@example.org:me/mysite.git (fetch) origin email@example.com:me/mysite.git (push) ac firstname.lastname@example.org:mysite.git (fetch) ac email@example.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
* [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!
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.Acquia Developer Center April 13, 2012 May 13, 2016