Building a Drupal site with Git

12
Building a Drupal site with Git Diagrams and Notes Jan 2013 Provided by dumbass Please note this is currently a documentation for discussion- it has not been reviewed yet. Please leave any useful comments This document should be used in conjunction with the excellent tutorial on Drupal.org

Transcript of Building a Drupal site with Git

Page 1: Building a Drupal site with Git

Building a Drupal site with GitDiagrams and Notes

Jan 2013

Provided by dumbass

Please note this is currently a documentation for discussion- it has not been reviewed yet. Please leave any useful commentsThis document should be used in conjunction with the excellent tutorial on Drupal.org

Page 2: Building a Drupal site with Git

Server with user fooproject

* This directory is not the working tree, where you edit and commit code. Rather, it is simply the central location for the git objects and history.

public_html

fooproject.git*

$ ssh [email protected]$ cd ~$ git init --bare fooproject.git

Creating the Central Repository

Page 3: Building a Drupal site with Git

Local machine

fooproject

$ git clone git://drupalcode.org/project/drupal.git fooproject$ cd fooproject$ git checkout 7.0

This command clones a copy of the latest Drupal code into a local folder named fooproject

Locally Cloning Drupal

git://drupalcode.org/project/drupal.git

local_development_environment

TIPBefore you issue these commandsEnsure you are in the correct directory where you want to install your local Drupal installation by navigating to the correct directory by using the usual

$ cd path/to/my/directory

Page 4: Building a Drupal site with Git

Serverpublic_html

fooproject.git*

Local machine

local_development_environment

fooproject

How your setup should look

Page 5: Building a Drupal site with Git

Local machine $ git remote rename origin drupal

$ git remote add origin path/to/your/central/git/repo

(example: ssh://[email protected]/home/fooproject/fooproject.git)

Rename the original origin remote (the drupal.org Drupal project repository) to ‘drupal’

Updating Remotes

TIPTo end your current remote session and start working locally useCTRL+D

Page 6: Building a Drupal site with Git

Creating a Working Branch

Local machine

local_development_environment

fooproject (fooproject)

$ git branch fooproject$ git checkout fooproject

You now have a git branch called fooproject. You can use this fooproject branch as a working branch to add contributed and custom modules and themes to your site. Consider it the equivalent of the default Git ‘master’ branch for your project.

Page 7: Building a Drupal site with Git

At this point, you should complete the Drupalinstallation process to get a working local installation.

Complete local installation of Drupal

Local machine

Page 8: Building a Drupal site with Git

local_development_environment

fooproject (fooproject)

Pushing Code to the Central Repository and Completing Initial Deployment

Local machine

$ git push origin fooproject

Serverpublic_html

fooproject.git (fooproject)

Page 9: Building a Drupal site with Git

Pushing Code to the Central Repository and Completing Initial Deployment

$ git clone --branch fooprojectssh://[email protected]/home/users/fooproject/fooproject.git fooproject_dev

Serverpublic_html

fooproject.git (fooproject)

fooproject_dev

This fooproject_dev version could exist on another server. But is a sub –directory in this example. Once you have completed your initial pull you will see the Drupal file structure on the server

Page 10: Building a Drupal site with Git

Now, you have a fooproject_dev directory that you can use as the root of a new virtual host. You can proceed through the normal Drupal installation process using this development copy of your site and a separate database for it. Repeat this process for the Staging and Production environments - we’ll assume that they live on the same server in directories fooproject_stg and fooproject_prod.

Complete dev installation of Drupal

Server

Page 11: Building a Drupal site with Git

Pushing Code to the Central Repository and Completing Initial Deployment

public_html

fooproject.git (fooproject)

fooproject_dev

fooproject_stg

fooproject_prod

Server

Page 12: Building a Drupal site with Git

Staging and Production - Tag Based Deployment

$ git tag prod_20110419 ## Creating a tag from the current commit. You can specify a commit here if you wish.

Local machine

$ git push origin prod_20110419

$ git pull $ git checkout prod_20110419

Server