Clients and prospects often ask us how we, as an agency, maximize efficiency with our development resources when working with Magento. While there are many factors that go into this, one of the first things that we like to point out from a process standpoint is the use of version control.
In this blog, I’m going to walk you through the basics of version control for Magento from a technical approach as well as the two systems that we use in-house with all of our clients for version control and code deployment: Git and Beanstalk. Afterwards, I’m going to walk you through a few use cases of how version control can be excellently applied to Magento. Enjoy!
Why Use a Version Control System with Magento?
If you’re a developer, have you ever tried working on a Magento instance of a website at the same time as someone else? Are you constantly asking “hey, are you in this file right now?” I am sure you are used to dealing with the frustration of having to coordinate with other developers to make sure neither of you overwrite another’s changes.
Even if you were making your changes in a separate Magento development instance, it is entirely too easy to overwrite someone else’s changes and lose hours of work. What happens if you accidentally overwrite a critical change and you don't have a backup? Yes, hindsight is 20/20 and you should always be backing up your data but it does happen to even the most well-intentioned of folks. There must be a better way to work!
This frustration can be completely mitigated if you take advantage of a version control system, or VCS. I am sure you have heard this term being thrown around but what is it? VCS? Does it have anything to do with a VCR? Not quite...
Version control systems allow us to keep a history of all changes made to a file (or many files). At any point, we can check this history to see when a certain change has been made. It also allows us to merge several versions of one file. No longer do you have to ask a coworker to get out of a CSS file while you make some quick changes... #winning.
Git – Groove’s Version Control System of Choice
Now, there are several different systems that you can use for version control, but the most popular and widely used is Git. An important note: Git and GitHub are two different things.Git is the VCS while GitHub is a hosting service for repositories (more on these below) that utilize Git.
Git is a “distributed version control system” (DVCS), which means that instead of there being one centralized server that holds all of the files (CVS, Centralized Version Control), an entire repository is cloned onto your local machine (excluding ones you specifically mark to ignore).
This function allows Git (and other similar DVCS’s) to be far superior in our opinion. Each cloned copy is essentially a back-up of the repository and contains a full history of all commits made to the project up until the moment of cloning. Because the files are all located on your own machine, you can make changes and work on the project without being connected to a network. Here's a visual representation of a distributed version control system which may help:
Overall, utilizing Git or any other VCS allows developers to avoid errors and avoid the bottleneck of waiting for another developer to get out of a file.
Beanstalk – Groove’s Repository & Deployment Tool of Choice
Project files from Git and other VCS’ are stored in what’s referred to as a repository. Imagine a bucket of goodies that allows people to check out and put back in little bits of information. Every action you make to that bundle of goodies, whether it is editing a file or deleting one, is saved as a “commit” and can be accessed at a later date.
While you may have heard of GitHub, our repository of choice at Groove is Beanstalk.
Here’s a few reasons why we really like Beanstalk:
- Navigation - Interface is super easy to navigate with no server administration necessary
- Deployment – Ability to easily deploy changes directly from your repositories to (S)FTP and SSH in one step from source code
- Browse Files & Changes - Ability to easily browse and view changes to every file that’s been committed
- Code Editing - Ability to easily make and commit changes directly in the web interface of Beanstalk
- Blame Tool – Ability to view history of every file and who was responsible for each line of code
- Integrations – Ability to integrate with popular agency software like Basecamp, Campfire, Harvest, among others
- Trusted Physical Security – Beanstalk is hosted in a SAS70 Type II certified Rackspace data center, so there’s no need to worry about down-time or security threats
As mentioned above, you can use Beanstalk to deploy your code changes which is much more efficient (and time-saving) than pushing code manually. The benefits of deploying code using Beanstalk include:
- Ability to set up multiple services behind different environments, i.e. you may have one staging server but three production servers
- Ability to set up automatic deployment schedules so that every time you push a commit to your repository, the change gets automatically deployed to your server
- Ability to manually control deployments in the event that you want to actually push a button when pushing code to a live production server
Read Beanstalk’s Deployment Best Practices guide and knowledge base article for more details.
A Few Key Terms to Know when Utilizing Version Control
Before I walk through a few use cases of when version control is a no-brainer for Magento, it’s important that you understand a few key terms:
Branching allows you to create a copy (or snapshot) of a product or file set within your repository that you can then modify in parallel without altering the main set (often referred to as your "trunk"). You can work in these branches to test new features or versions without affecting your trunk.
If you’re utilizing branching and are comfortable with the new branch that you’ve been experimenting with, you have the ability to actually merge that with your trunk. As I'll dive into below, this is an excellent way to handle Magento upgrades.
Tagging is generally used for creating a snapshot of a project in time. So, say you want to mark a particular revision (i.e. 1.0, 1.1, 2.0, etc.) so that at any time you can recreate a certain build or environment. Boom, you can do this with tagging.
Two Excellent Use Cases of Utilizing Version Control with Magento
Upgrading Versions of Magento
In a perfect world, upgrading versions of Magento would be as easy as pushing that “upgrade button”. However, most times, it’s much more complicated than that and filled with many road bumps, particularly if you’re utilizing a lot of extensions. Using version control, you can create a branch (told you I would be dropping these terms) of your Magento instance and upload all new core files here. Then, you can deploy these files to a staging environment and see how everything goes. If there are things that need to be fixed or edited, you can add those to the branch and safely continue to work without ever harming your live site. Once everything is running smoothly, you can then merge that branch into your trunk. And, in the event that you want to test more extensions with this new upgrade, you can simply create tags of your initial branch that worked well with the core files and continue to deploy and troubleshoot.
Deploying Extensions & Theming
Deploying extensions and also making adjustments to themes in Magento can be very complex. Often times, one small change to code can completely break an extension or theme. Using version control, however, you can safely see what files have been changed and when so that you can safely recover your backup. This will save you a ton of time and also spare you a ton of grey hairs.
Whether you’re handling code changes to your Magento site in-house or leveraging an agency to do this for you, you should always utilize a version control system, no exceptions. Among the many benefits, which I discussed throughout this blog, version control will allow you to develop safely and collaboratively while maximizing time efficiency. As for systems that we recommend here at Groove for leveraging version control, that would be Git and Beanstalk.
Need help with your own Magento development or setting up a version control system? Don’t hesitate to give us a shout!