git¶
You can use Simple Hosting’s git service to upload your source code and deploy your application, including installing dependencies, to your Simple Hosting instance.
Your instance’s Control Panel also has a web-based graphical interface to browse your git repository.
Learn all about using the Simple Hosting git service in this article.
Prerequisites¶
You’ll need to have git and an SSH client installed on your computer in order to use the git service
Overview¶
Simple Hosting’s git service hosts remote git repositories for you. Additionally, it allows you to build and deploy your application on your instance, installing any dependencies you declared.
On PHP instances, every Site has its own independent git repository, named after the domain that corresponds to the site (ex: example.com.git
). On Node.js, Python and Ruby instances, there is only one git repository, which is named default.git
.
After adding the repository as a git remote
to your project directory, you’ll be able to git push
your code to the git service. By default, the service will expect you to use the master
branch, but you can push any branch or tag that you wish.
You can also git clone
a repository from our git service and use any other features you’d expect from a remote git server. You can truly use it as a version control system.
Once the files have been pushed to the service, they become available for deployment with the deploy {repository}.git
command, which is executable via SSH on the same address as the git service.
The deploy
command will build your application and copy the application files to your instance. Application dependencies can be declared using the supported package managers for each instance-type and will be installed as part of the deploy process: Composer for PHP, NPM for Node.js, pip for Python, and Bundler for Ruby.
All these steps are detailed in the sections below.
git service URL¶
In the examples that follow, the git service URL is represented by a $GIT_URL
bash variable. You’ll find the actual URL in your instance management page.
On PHP instances, you’ll find it in the “Sites” section within each Site’s page.
On other instances, you’ll find it the “Deploy” section of your instance’s management page.
The format of the git service URL is always as follows:
GIT_URL="ssh+git://{instance_id}@git.{datacenter_id}.gpaas.net"
Authentication¶
You can authenticate on the git service using your instance’s password (default behaviour) or public SSH keys.
If you choose to use your instance’s password, you’ll need to provide your password whenever you interact with the remote git service, for example to perform git clone
, git push
or deploy commands
.
When using SSH key authentication, your system should be able to provide the correct public key to the git service whenever necessary. This is the recommended way to authenticate, as it is convenient, secure and enables you to write automated scripts.
Create a repository¶
Here are a couple of examples to create your repository for all instance types: PHP instances, where each Site has its own repository, and other instances, where only a default
respository exists.
Once the repository has been created, you will be able to see it in your instance’s Control Panel using gitweb, an open source web-based graphical user interface (you will need to reboot your instance after you create a repository for the first time on your instance).
Example for a PHP instance¶
This example shows you how to create a repository locally to upload code to a PHP instance. It uses a Site called example.com
. You can simply replace the Site’s domain with one your domains, including the test domain that was automatically created for you.
$ mkdir example.com
$ cd example.com
$ git init
$ git remote add gandi $GIT_URL/example.com.git
$ mkdir htdocs
$ echo "Hello world" > htdocs/index.html
$ git add htdocs
$ git commit -m "first version of index.html"
$ git push gandi master
On PHP instances, the root of your repository is not the directory used by the Apache httpd server to serve files to web visitors. Consequently, in order for your files to be accessible via the web, you must put them in the htdocs/
directory, to be created at the root of your repository.
Example for other instances¶
This example shows you how to create a repository on a Node.js, Python or Ruby instance using a dummy text file. Please refer to their respective documentation pages to learn how to structure your project files.
$ mkdir myapp
$ cd myapp
$ git init
$ git remote add gandi $GIT_URL/default.git
$ echo "Creating my repository" > test.txt
$ git add test.txt
$ git commit -m "Add a text file"
$ git push gandi master
Clone a repository¶
Copy a remote repository to your computer using the git clone
command:
$ git clone $GIT_URL/{repository}.git
By default, the git clone
command will create a directory with the same name repository (ex: example.com
or default
) and copy files into it. If you want to specify another name for the local directory, without interfering with any git settings, simpy add it to the command:
$ git clone $GIT_URL/{repository}.git my_app
Deploy your code¶
This command will perform a git checkout in the target directory on your instance. It will also install any dependencies using the packager manager: Composer for PHP, NPM for Node.js, pip for Python and Bundler for Ruby.
$ ssh $GIT_URL 'deploy {repository}.git'
Remember that the {repository}
placeholder corresponds to a Site’s address on PHP instances (ex: example.com
), but is always default
on other instance types.
The deploy
command assumes that you want to deploy the code checked into your repository’s master
branch. If you wish to deploy another branch or tag, for example a production
branch, you can add it to the end of the command:
$ ssh $GIT_URL 'deploy {repository}.git production'
Bemerkung
The use of Git submodules is not supported at the moment.
Dealing with existing files¶
Any directories already present in the target deployment directory must at least have the same write access of the user, so that the files can be replaced during the deployment (ie. chmod 644
). This action is to be carried out if you encounter an error like:
error: unable to unlink old 'htdocs/sites/default/settings.php' (Permission denied)
Additionally, you may want clean up your target directory. The following command will execute a git clean operation on your directory and delete any files that are not tracked by git or not listed in your repository’s .gitignore
file:
$ ssh $GIT_URL 'clean {repository}.git'
Warnung
Keep in mind that if your web application has user-upload directories, file-caches, or untracked configuration files that you want to keep on the server (ex. environment specific configurations / secret keys), those should be added to your repository’s .gitignore
file prior to running the clean command.
Delete a repository¶
To completely remove a repository from your instance, delete its directory via sFTP or the Emergency Console.
The directory’s path via sFTP looks like this :
/lamp0/vcs/git/{repository}.git
Via the console :
/srv/data/vcs/git/{repository}.git
Windows Users¶
Windows users can use the msysgit git client, for which a third-party tutorial is available at http://guides.beanstalkapp.com/version-control/git-on-windows.html
SSH Key Fingerprint¶
The SSH key fingerprint for the git endpoint is:
35:e0:5a:a9:54:12:55:6b:ce:41:8c:c1:9e:35:1d:f6
Resources¶
Official git website: http://git-scm.com/
Official git documentation: http://git-scm.com/book/en/