Search the site:

Copyright 2010 - 2023 @ DevriX - All rights reserved.

Quick Intro to Git for WordPressers    

Git for WordPressers

Nowadays a version control system, also known as VCS, is a must-have tool in your development arsenal, no matter whether you are a software developer, a web developer or a designer. Having a history of your changes is a very important part of your workflow.

One of the best version control systems for WordPress at the moment is Git. This powerful combination provides numerous tricks right out of the box to make your life easier.

What is Git?

What is Git and what does it do actually?” is a common question, asked not only by non-developers but by some developers, too. So before getting into more details, let’s make sure we have that question sorted out.

Git is an open source project, originally developed in 2005 by Linus Torvalds, the famous creator of the Linux operating system kernel. Since then, Git is being constantly improved and is now actively maintained as the currently most widely used version control system in the world.

There are other once-popular VCSs like CVS (Concurrent Versions System) or SVN (Subversion), but what they lack Git has is the distributed architecture. This means that in Git, every developer’s working copy of the code is also a repository that can contain the full history of all changes, rather than having one single place to store it.

That’s essentially what Git is. Now, let’s say a few words about what it does and what it gives you. Having a history of all the changes you have made gives you a lot of flexibility as well as safety. Why? Well because…

  • You can experiment with new features freely without losing the stable version of your code.
  • If something goes wrong, you can always revert to a previous version.
  • You can have your code split into different branches so that it’s well organized.
  • You can track your changes, progress and growth of your project.
  • You get informed by Git when there is a possibility of having lines of code overwritten by others (the so-called “merge conflicts”).

  • Git is just the best.

Should You Use Git for WordPress?

You definitely should. Assuming what Git provides, the obvious answer is “Yes”. It’s always a good idea to use a version control system and Git in particular. No matter whether you make changes to your theme or a child theme, active plugins or developing new ones, using Git makes your life easier. Moreover, it’s used for the development of the WordPress Core itself.

There is a lot of hypothetical situation where Git will “save your life”.

For example:

You are working hard on a new feature when suddenly your physical machine dies and all your progress is lost – you have it in Git, though.

You have done a few styling or code changes, but later on, you find out that this breaks the design for a few pages or it even takes down the whole site – you can revert from your latest changes to your Git history quickly and then handle the situation with a lot less tension.

How to Use It? Command Line vs. GUI?

When it comes to that question, the best answer would be: It’s up to your personal preferences – both have pros and cons. In both cases, you get the full functionality of Git. The difference is the ease of use and how good you’ll get to know the features.

GUI makes things easier to visualize, setting up and managing the remotes, merges and conflicts of a merge, picking the files to push or pull the latest changes. GUI also shows you the state of the Git tree, containing all the branches you currently have. This can also be tracked in the web clients of most of the version control systems.

On the other side, if you use Git via command line commands, you will get a better understanding of how the system works and exactly when to use what. It would probably be better to start with the command line and then switch to GUI to make it simpler once you know what you are doing. This way you will make yourself independent of using any specific application.

If you chose to use a GUI application, here is a list of such, depending on your operating system:

  • Linux
    • GitKraken
    • GitGUI
  • Mac
    • Tower
    • Crisp
  • Windows
    • SmartGit
    • Source Tree
    • Tortoise Git

This, however, is just an example list. There a lot more different applications and many of them are actually cross-platform. Once you get to know the basics you can pick the one that suits you best.

Basics of Git Usage

First of all, you should pick a host for your repository. Examples of such are GitHub, BitBucket, GitLab and many others. Once you have that ready you should learn some commands. Git comes with a ton of them to use once you fully understand how to use it, but for beginners, there are some that are a must. We will provide a short list of line commands to start with.

Having created your repository it’s time to set it up locally.

  • git init – this will tell your computer that the current folder will contain a Git repository.

  • git remote add upstream <url> – this will set up the link to your remote project so that Git knows where to push your changes to.

Now that you are ready setting it up. Now to push some files to have them in the repo.

  • git add <filename> – this will stage the file to be ready for the push.
  • git commit -m “<commit message>”– running this command will prepare all staged files to be pushed with the entered message as a description.
  • git push upstream <branch> – after you run that, your changes will now be available in your repository hosting. As you can see, there is a branch parameter but using different branches is a more advanced subject, so as a beginning, you could enter master (the master branch).

Git and WordPress

Since we are talking about Git for WordPressers, then a legit question is why not use a plugin. Of course, there are already developed plugins for Git integration in WordPress and two of the popular ones are Revisr and Gitium.

To put it simply, they provide you Git controls directly from the dashboard of your project. The former mentioned plugin has one unique feature though — it gives you the option to backup your database. This way, if you need to roll back to a previous state of your code, you will be able to go back to the same stage.

Are you using Git when developing on top of WordPress? Share your experience in a comment below.

Leave a Reply

Your email address will not be published. Required fields are marked *