Using Git with WordPress and SiteGroundPosted on Updated on
Making changes to a live website can be one of the most nerve-racking moments for an administrator. One can never predict when some unknowable factor in is going to play a role and screw up your installation. Whether it is a configuration change, a new plug-in, a new theme, or something else, website administrators have to take a lot of care to always have a backup available to them. But in a professional setting, this is not sustainable particularly if you have more than one person maintaining the code base. I can speak from personal experience that my application development was revolutionized when I started using versioning systems. No longer do you worry about accidentally screwing something up because it’s so easy to revert back to any version in the past.
I’ve often wanted to implement a version control system like git onto WordPress, but haven’t really gotten around to it. I would have to set up my own git server and all that. However, when I moved to SiteGround I was pleasantly surprised to see that they offer git for WordPress right out of the box! It’s as simple as clicking a button to create a repository. The only difficulty I had was in cloning it to my desktop computer – and I finally managed to figure it out. Doing all your development on a local machine and then pushing the changes to a live server has the advantage of knowing that nothing short of database corruption poses a real threat to your site. Everything else can be reversed.
So let’s see how to enable git on SiteGround and how to clone our first repository.
When you log into your SiteGround cPanel, navigate down to the icon called “SG-Git” as shown here.
If you set up your WordPress installation properly and have had it recognized by SiteGround, you should see it in the list at the bottom of the next screen. Under the “Actions” heading, you will have a button called “Create Git Repository”.
This will bring up a lightbox informing you that native WordPress updates might be impacted, but I don’t really see how that can happen. SiteGround informs you that even if this is the case, the auto update tool from within the SiteGround account will be able to update the installation. Worst-case scenario, I can always delete the git repository, update WordPress, and create it again.
In any case, I’m excited to try out this functionality so I’m willing to take the risk! Once you click the “Continue” button on the lightbox, SiteGround will show you a pop-up with two important pieces of information:
- The SSH key for accessing git
- The clone command required to replicate the repository on the local computer
If you’ve already created one or more SSH keys to access your SiteGround account as shown in my earlier tutorial, the first piece of information will simply be one of them. We’ll see how to use the second in a moment.
Importing the SSH Key into Git Locally
If you haven’t already, download and install the standard Git installation for Windows. Now as in the tutorial I showed earlier, download puttygen.exe after having copied and pasted the SSH key from the previous screen into a blank notepad file with the extension “ppk”. If you’ve set up SSH access earlier, then you already have the PPK file ready to go.
Fire up puttygen.exe, click “Load” and select the PPK file as shown below. Then go to “Conversions”, click “Export OpenSSH Key” and save the file in your “.ssh” directory of your git installation. In this example, I’ve chosen to call the exported OpenSSH key “wordpress_git”. You can make out that it’s the right directory because the other files in it will look like this:
The next step is to add the SSH key with the “ssh-add” command. Simply type in:
Or whatever you’ve named your key. Enter the passphrase for your key and git will add your identity as shown in the screenshot below:
Now that you’ve imported your key into git, you can use the clone command displayed when you first created the git repository like this:
This should clone your remote WordPress installation into your local directory – let me tell you, it’s a good feeling when it works out! And just to verify that this is indeed what happened, here’s a screenshot of my WordPress files in my local PC folder:
Pretty neat huh? This is not the place where I go into the details of how to stage and push changes using git. That’s a different tutorial altogether, but you can see for yourself how simple it is to set up a git repository on WordPress and clone it using the SiteGround tools.
One Reply to “Using Git with WordPress and SiteGround”!
but what about the database? how do i deal with that piece?