A Git Workflow with Pressjitsu
Version control is the best way to keep track of all your code in a web application, and Git is by far the most popular choice among WordPress developers these days. We use Git every day here at Pressjitsu and today we’d like to introduce a workflow to help developers manage and deploy their code more efficiently.
Deploying with Git
Note: if you haven’t used Git before, we recommend you go through the basics first, you’ll need to know the concepts of committing, pushing and pulling code to follow along.
Git has been installed on every Pressjitsu node ever since we launched, but recently we started working on integrating Git repositories into our hosting control panel, as well as a set of custom command line tools.
With Git Workflow enabled on your account you’ll see a list of all your recent commits, updated automatically whenever you push something new. The currently deployed commit will be highlighted to indicate what is currently live in production.
Deploying a commit is as simple as clicking a button in the web interface, or by using the CLI tools if you’re a command-line geek. If you’re confident in the code you’re pushing, you might as well setup automatic deploys whenever new commits appear in your master branch, although we don’t recommend this for large high-traffic sites — it’s always best to review at least the commit headlines before dropping the code on live visitors.
Although not 100% atomic, deploys are pretty fast, usually within a few seconds. And if something went wrong, deploying a previous revision is just as easy, and don’t worry, even if the site is completely broken, deploys will still work, since they’re powered by our service nodes, which are independent from our customers’ servers.
When keeping your code under version control, there are always a few things to keep in mind, especially when deploying, and most definitely when multiple web servers are involved (our Enterprise plan).
This one is fairly tricky, because our old cowboy-coding habits tend to get in the way.
The best way to avoid local changes is to try and never SSH or SFTP onto your server, but if you do, always check the output of
git status before leaving. Make sure you’re not leaving modified or untracked files around.
Having snapshots of your entire site available at all times is really great, but not so great when you’re working with version control. It’s always best (and easier!) to restore the codebase simply by checking out a different commit.
We’re currently working on a much better integration between our backups system and the Git Workflow. You will soon be able to restore individual components of a backup, and Git repositories will be backed up separately.
GitHub or Self-Hosted Repos
If you’re a heavy Git user, chances are you’re already using GitHub for your project, so you might not want to switch over to our hosted repositories simply to get deploys working, but guess what, you don’t have to!
Git is a distributed version control system, which means a copy of the project repository may live in several places at the same time, and using Git with both GitHub and Pressjitsu is as simple as adding a new remote for your existing project:
$ git remote add pressjitsu email@example.com:project.git $ git push pressjitsu master
This will sync all your existing commits with your Pressjitsu server, and they will be available for deploys immediately.
Git Workflow is an experimental feature we’re working on here at Pressjitsu. If you would like early access, all you have to do is open a support request via your control panel. Just ask for Git Workflow and we’ll enable it for your account, as well as help you set everything up.