Cotonti / Open Source PHP Content Management FrameworkContent Management Framework

Documentation / Administration / HOWTO Maintain your Cotonti site with Git

A handy replacement for FTP with automatic updates from Cotonti repository

This guide is aimed at Cotonti site owners who whish to achieve at least one of the following goals:

  • Automatically pull updates from Cotonti repository and upload them to their site without having to check for changes and upload via FTP.
  • Develop the site together with teammates and avoid overwriting each other's changes.
  • Sync changes between several sites.
  • Build wesite deployment chain with Git.

Requirements:

  • SSH access to your website server.
  • Git installed on your local development computer and on your website server too.

Examples of actions in this guide are given as shell commands. On client-side you can substitute some of them with GUI client actions.

Warning: if something goes wrong or you make a mistake while syncing with Git it is better to restore you files from a backup. So make sure to make one before trying any of the following scenarios.

1. Use Case 1: from Cotonti repository to your local copy and then to your site

Let's create a local Git repository by cloning one of Cotonti's branches into current directory on your computer. To clone from latest Siena/master:

git clone -o cotonti git://github.com/Cotonti/Cotonti.git .

The option -o says to name the reference to Cotonti repo as "cotonti" rather than "origin" (default in git) to avoid confusion. The point at the end means that it will be checked out into the current directory, replace it with another path if necessary.

If you use Genoa branch, use this command:

git clone -o cotonti -b genoa git://github.com/Cotonti/Cotonti.git .

The -b option sets the branch name to checkout. Default is master (siena).

After cloning, if you want to switch to specific release tag "cotonti-x.y.z", use Git checkout command with the following options:

git checkout cotonti-x.y.z

Now you have a local copy of Cotonti's repository. You can manipulate with it any way you like. Useful resources about using Git in your daily life are listed in References section of this article.

Once you are ready to setup a Git repository on your remote site and push your synced Cotonti there, do it with this scenario:

ssh -l your_login example.com
mkdir site.git && cd site.git
git init --bare
echo -e "#!/bin/sh\nGIT_WORK_TREE=/path/to/htdocs git checkout -f" > hooks/post-receive
chmod +x hooks/post-receive

Line 1 is connecting to your site's SSH. On lines 2-3 we create a new location for git-sepcific files and initialize a new repo therer. Line 4 creates a script which will automatically apply changes to the site files, replace /path/to/htdocs with an actual path to your Cotonti site on this server. 5th line makes this script executable.

Then you can get back to your local repository and push it to the server:

git remote add site ssh://your_login@example.com/path/to/site.git
git push site master

Replace "master" with "genoa" or another branch you currently use.

After that you will be able to use synchronization commands described in one of the following sections.

2. Use Case 2: from existing site to your local copy, then sync with Cotonti repository

In this case we assume that you have already initialized site.git repository for your remote website, for example with a script given in the previous Use Case. If you have initialized a repository on your server alone but you have not added any files there to be monitored by Git, then you should do it by entering your site's htdocs and running "git add" command there:

ssh -l your_login example.com
cd /path/to/htdocs
GIT_DIR=/path/to/site.git git add .
GIT_DIR=/path/to/site.git git commit -q -m "Added site files"

Note: GIT_DIR is necessary in git calls on server because Git files are stored separately from site files on server.

Once your remote site.git repository is filled and up to date, your teammates can clone it to their own local copies:

git clone -o site ssh://user2_login@example.com/path/to/site.git

Specify "-b genoa" argument if using Genoa branch. They can also add a Cotonti's repository to git remote list too:

git remote add cotonti git://github.com/Cotonti/Cotonti.git

Then they can just pull and push like you do, necessary commands are given in the next section.

3. Update your local copy and site

If you have configured your local and remote repository like described above, you can use the following commands in your daily workflow.

Note: if you use Genoa branch rather than Siena, subsitute "master" with "genoa" in all the given commands. 

To update your local copy with latest changes from Cotonti repository:

git pull cotonti master

To apply recent changes to your site:

git push site master

To grab latest changes your colleagues have pushed to the site:

git pull site master

Happy deployment with Git!

4. References


1. gazigokmen  2011-10-20 17:51

Thanks: 0

m

Total: 1, on page: 1

Only registered users can post new comments