Git is an efficient and popular distributed version control system. You can use git to deploy and manage application code on your Application Container.
Setting Up Git
To use Git, you first need a Git client. On Linux, Mac and the MSys or Cygwin environments on Windows, you can use the git command line tool. If you prefer a GUI based tool, several options exist, including:
- TortoiseGit for Windows
- GitX for Mac OS X
- EGit, a plugin for Eclipse allowing direct access to Git repositories from within Eclipse
In this article, we will demonstrate simple usage of the command-line Git client - however the same principals apply to other clients.
You can download Git from http://git-scm.com/download. If you use Linux, Git is probably available through your package manager. Mac OS X users can easily install git using MacPorts.
To test that Git is properly installed on your system, type the following command:
$ git --version
If all is well, you should see the git version printed out.
Cloning your Application form Zend Developer Cloud Platform
Once you have a Git client set up, and an application deployed in Zend Developer Cloud Platform, you should clone that application ("clone" is more or less Git's equivalent of Subversion's and CVS's "checkout" command) to your local working environment.
In your Application Container's applications list, click on the 'Git' icon next to the application you want to work on:
Copy your application's Git repository URL, and open a command line terminal window. In the command line, type:
$ git clone <git repo URL>
Where <git repo URL> is the URL copied above. You will be asked for your password - type in your container password and hit enter. A new directory should be created with a local git repository containing your code. You may now change into the cloned directory and start modifying your application code.
Note: if you encounter SSL certificate validation errors, you may need to update your cURL CA certificate bundle. This process is system dependant and is not a part of the scope of this document. As a temporary workaround, you may disable SSL certificate validation by setting the GIT_SSL_NO_VERIFY environment variable to '1', for example:
$ GIT_SSL_NO_VERIFY=1 git clone <git repo URL>
Configuring your Git Client
Once you have a local clone of the repository, you should configure your Git client to avoid protocol errors when working with your Zend Developer Cloud container.
Make sure you set the the HTTP post buffer to a large value by adding the following lines to your local
[http] postBuffer = 524288000
In Linux and Mac, you can edit
.git/configunder the cloned repository path directly using your preferred text editor.
In Windows, if using TortoiseGit, you can access the local
.git/configby opening the TortoiseGit settings window, navigating to Git -> Config, and clicking on "Edit local .git/config".
Modifying Code and Pushing Updates
Once the application is cloned to your local disk, you can start modifying and adding files. Once you are ready to commit your code, use the git add and git commit commands to commit changes.
For example, if you have created a new file named 'index.php', add and commit it like so:
$ git add index.php$ git commit -m "Adding index.php"
This commits changes to your local repository (this is different from single-repo SCM systems like Subversion, where 'commit' actually pushes changes to the server). After making several commits, your next step would be to push changes back to the origin repository. In the case of the Zend Developer Cloud Platform, pushing code to your origin repo will update your deployed application on the web server.
To push code back to the server, use the git push command:
$ git push origin master
In this case 'origin' refers to the repository from which the local copy has been cloned (in Git you may have multiple remote repositories, and 'origin' is the default name of your origin repository), and 'master' is the name of the branch you want to push - again 'master' is the default branch.
After you issue the push command, you should see your application updated.
Pushing an Existing Git Project into Zend Developer Cloud Platform
But what if you are already using Git to manage your project, and you want to push an existing Git project into your Zend Developer Cloud Platform application container?
In this case, you should add your Developer Cloud application Git repository a new remote repository to your local working repository, merge your existing project into it and push it back to the server. While this requires slightly more knowledge of Git, it is not a very complex process:
$ git remote add zendcloud <git repository URL> $ git pull zendcloud master $ git push zendcloud master
The first command, remote add, adds a new remote repository to your local git working repository. Then, the git pull command pulls merges content from the newly added remote repository (aliased "zendcloud") to your local working copy. Finally, the push command pushes the merged code, including the code previously existed in your Git project, into the Zend Developer Cloud Platform git repository. Just like before, this will automatically update your deployed web application.
More about Using Git
This tutorial covers basic Git usage with Zend Developer Cloud Platform. You should get yourself better familiarized with Git if you want to enjoy its full power.
To learn more about Git, we recommend checking out some of the following resources:
- The official Git tutorial and other documentation resources at git-scm.com
- The Pro Git book and Blog
- The github.com help section