Setting Up A Git Workflow

A lot of my work involves developing HTML/CSS prototypes for often complex site designs and custom web applications. The workflow involves working with clients and other team members to iteratively develop concepts through various stages of the site development process:

  • Site Maps
  • Wireframes
  • Layout Concepts
  • HTML/CSS Templates

The process involves developing everything locally and then pushing the ideas, layouts and code up to a area (subdomain) dedicated for design mockups. We’ve just installed Git on this server so that I am able to develop locally and maintain remote repositories on the subdomain server that can be used to pull changes for clients and colleagues to view on this subdomain. While GitHub is great, hosting private Git repositories requires a paid account that has limit on the number of repositories and contributors that can be involved on these projects.

Most of my development on GitHub involves an open source CMS project called Symphony. For our client work, I don’t always have the luxury of sharing our code with the world. Here’s how I’m starting to deal with our private repositories.

Create the Remote Repository

The first step is to create a remote Git repository on the staging server. Create a bare Git repository by logging into the server through SSH and running the following commands:

              ssh username@example.com
cd /path/to/private/directory
mkdir git
cd git
mkdir repository_name.git
cd repository_name.git
git --bare init

            

Create the Local Repository

If the local repository has not been created, create the Git repository, commit a file or files to the repository, configure the remote repository and push the repository up to the remote repository. If you want to create a repository from an existing set of templates, run the following commands:

              cd /path/to/local/directory
git init
git add .
git commit -m "Initialize repository"
git remote add origin ssh://username@example.com/path/to/private/directory/git/repository_name.git
git push origin master

            

Clone the Repository on the Staging Server

To sync the staging server with the local repository, just clone the repository:

              ssh username@example.com
cd /path/to/html/directory
git clone /path/to/private/directory/git/repository_name.git

            

Sync Local Changes with the Staging Server

Then, whenever changes are made to the local repository, push the changes to the remote repository:

              git add .
git commit -m "Changes to the repository"
git push origin master

            

And pull them from the remote repository to the staging area.

              ssh username@example.com
cd /path/to/html/directory/repository_name
git pull origin master

            

It’s a pretty painless workflow to keep files in sync between my local hosting environment and the staging server.