Git is the version control system (VCS) available for use with Cloud Platform. The following information will help you use Git to manage your Cloud Platform code repository.
Downloading a Git client
You will need a Git client installed on your local system to work with your code repository.
To download a Git client, use the method based on your operating system:
- MacOS: Use the Git OS X Installer. If you use the Homebrew package manager, run
brew install git
. - Windows: Use Git for Windows (
msysgit
, command-line) or TortoiseGit (GUI). - Ubuntu: Use the command
sudo apt-get install git-core
to install Git using the command line. Follow the installation options on the official Git website.
Basic Git commands
You can find several basic Git commands, customized for your Cloud Platform application, in the Cloud Platform interface:
- Sign in to the Cloud Platform user interface, and select your application.
- Select Actions > View Git Information.
The Git Information panel displays basic Git commands for your application you can use to clone a repository, stage modified files, commit changes, and push local commits to a remote repository. You can click the copy icon to copy a command to your clipboard and then paste the command into an SSH session.
You can also find procedures to help you start with Git in Checking out a local copy of your code and Sending updates to your code repository.
Git best practices
The following best practices apply to any application hosted in Cloud Platform, and can assist you in developing with Git:
- Creating a feature branch
- Committing branch changes
- Merging your feature branches
- Code placement in Drupal
Creating a feature branch
To create a branch for development work:
- Open a command prompt window, and then change the directory to the location that contains the clone of your code repository.
Switch to the master branch.
git checkout master git pull origin master
Create the feature branch with a name that describes the work the branch contains, and then switch to the new branch using the following commands, replacing
[feature_id]
with the name of your feature branch:git checkout -b [feature_id] git push origin [feature_id]
Create and use as many feature branches as needed to keep your development efforts separate from one another.
Committing branch changes
Whenever you want to commit your changes back to the code repository for the branch you’re working on, run the following command to commit the change locally:
git commit -a -m "Comment"
After you commit the change, send the change to the code repository (where [feature_id]
is the name of your feature branch):
git pull origin [feature_id]
git push origin [feature_id]
When working with your code, if you must run a Drush command that only affects one of your websites, ensure you use the --uri=site.example.com
parameter, where site.example.com
is your website’s complete website and domain name.
Merging your feature branches
To merge your feature branches into a single release branch for testing:
- Create a release branch from your master branch. You will use the release branch for feature integration and testing. Use the following steps to create the branch:
Switch to the master branch.
git checkout master git pull origin master
Create the release branch, and then switch to the new branch, using a command like the following.
git checkout -b [release-candidate]
Run the following command to ensure you have the most recent feature branch versions:
git fetch all
Merge each of the completed feature branches into your new release branch, using a command like the following:
git merge [feature_id] --no-ff
Push your release branch to the remote repository for testing.
git push origin [release-candidate]
Code placement in Drupal
As you develop each code branch, place code changes and additions in the folders appropriate for your version of Drupal. Placing your changes in other folders can cause serious problems for your repository, including merge conflicts Acquia cannot help you resolve.
Additional resources
For more information about how to use Git, see the following online resources:
- Git basics: Acquia’s article on the basics of using Git.
- Resources for learning Git: an Acquia Knowledge Base article with a list of valuable tutorials and references.
- How to apply and test a patch from Drupal.org using Git on Cloud Platform