A Very Brief Introduction to Version Control and Git

petersuhmThis post was contributed by guest author Peter Suhm. Peter is a web developer from the Land of the Danes. He is the creator of WP Pusher and a huge travel addict, bringing his work along with him as he goes.
 


Have you ever done this?

Most of us have.

Do you know what the technical term for it is? Version control. Your own, homemade, delicious implementation of version control!

Okay, how about this?

Version control right there!

What I’m trying to show with these two examples is that all developers use some sort of version control. Some use Ctrl-z to roll back to a previous version, some use a zipped backup in a Dropbox folder and some use a dedicated version control system (VCS), such as Git. All the things we are trying to accomplish by backing up our files, commenting out old code and stashing it away in another “final-FINAL” zipball has been taken care of already. All we need to do is to embrace these VCS tools that we have available in our tool belt.

Git is not complicated to use. It might seem difficult and overwhelming but in your day to day life you will probably use a maximum of 3-4 different commands. Learning how to use 3-4 commands to properly have version control of every single change ever made to your code base is a great deal compared to the “final-FINAL” approach.

Here’s what version control looks like:

This is a screenshot of the WordPress Git mirror on GitHub. Every time a change is made to the code base, it is recorded with Git and there is no need to copy the whole code base, throwing it into another folder, zipping it and naming it “final-FINAL-F-I-N-A-L”. If you dive into the WordPress code base on GitHub, you can find commits dating back to 2003, made by “someone” named saxmatt!

Let’s dive into one of these commits, as they are called in Git:

This is the diff (Git jargon for difference between 2 commits) for the “class-wp-widget-text.php” file. The red line is being replaced with the green line below it. No need to comment it out to save it for eternity, like in that other example. Git will do that for us and we can forever and always refer back to this commit to see what was replaced and with what.

Of course, the full WordPress code base is a large project with many collaborators. However, no project is too small to benefit from Git. Once you master those 3-4 commands, using Git in your day-to-day developer life becomes second nature, just like hitting Ctrl-s. It might not be obvious right now, but when you pull out an old project months or years later, having version control helps you catch up and gives you the confidence to change things without fearing disaster.

So I challenge you to learn Git! Not necessarily deeply, just a little bit.

11 Comments


  1. Who today still needs a primer on Git? Seriously asking.

    Report


    1. I think you’d be surprised how common the ‘final-FINAL’ approach still is. Among developer using some sort of VCS is common practice, but (especially) within the space of WordPress there still is a severe lack of understanding of these fundamental development practices.

      Report


    2. That’s not a very nice thing to say! But I hope you’ll enjoy the rest of your day! :)

      Report


    3. Seriously answering: people who haven’t used it, or don’t know much about it.

      You may not realize it, but a comment like that can make a less experienced developer feel intimidated or ridiculed. Not everyone knows as much as you, and that’s fine. Why not have a welcoming and helpful attitude? That makes the world a better place for everyone.

      Report


    4. I’ve been working with WordPress for almost 10 years. I’ve never used Git. So, me?

      Report


    5. Me too, I’m involved in web dev. more than 10 years, but never used Git. Now I’m learning first steps, experimenting with Atom editor.

      Some forums would ban for such comments right away because you do not contribute anything to the community, but spoil everything with your attitude…

      Report


    6. Many people would be surprised to know that many developers don’t feel the urge to use the next hyped tool or library. And guess what? We survive! I just started using git a couple years ago, and mainly as a backup for my plugins and themes.

      Report


    7. Me. I’m an old-school programmer still getting plenty of COBOL work. I’ve been trying to figure out Git and GitHub for the last two years and can’t find anyone willing to give me a 10 minute demo. They’re too busy fussing with a new wapoo for WordCamp.
      Thank you Peter Suhm for this great article, you probably know how rare it is.

      Report


  2. I am using git for various projects. But when we think to use it for WordPress, Personally I feel so many challenges related to database management for various versions.
    It will be more clear to me if anybody explain it to me that how we manage database for various versions for our development server, QC server and also at production in case of WordPress.

    Report


  3. Yes, my first thought about Git being a miracle that saves from comically named archives flooding the backup folder: What About the DB?
    Please someone recommend a workflow.

    Report

Comments are closed.