+44 0330 223 3428
Call Us
+44 0330 223 3428

WPTavern: A Very Brief Introduction to Version Control and Git

WPTavern: A Very Brief Introduction to Version Control and Git

This 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.



Source: WordPress

Related Post
WPTavern: WordPress 5.0.2 to Bring Major Performance Improvements, Scheduled for December 19

WPTavern: WordPress 5.0.2 to Bring Major Performance Improvements, Scheduled for December 19 Processed with VSCOcam with c1 preset WordPress 5.0.1 was released yesterday as a security release with fixes for seven vulnerabilities that were privately disclosed. It includes a few breaks in backwards compatibility that plugin developers will want to review. WordPress 5.0.2 will be […]

Read more
WPTavern: WPWeekly Episode 341 – Recap of WordCamp US 2018

WPTavern: WPWeekly Episode 341 – Recap of WordCamp US 2018 In this episode, John James Jacoby and I recap WordCamp US 2018. We discuss what’s new in WordPress 5.0.1 and when users can expect to see 5.0.2. We also chat about the new path that WordPress is on and where it may lead. John shares […]

Read more
WPTavern: WordCamp US 2019 to be Held November 1-3 in St. Louis

WPTavern: WordCamp US 2019 to be Held November 1-3 in St. Louis photo credit: Wikimedia Commons Dates for WordCamp US 2019 were announced today, less than a week after wrapping up a successful camp in Nashville. Unlike all previous years held in December, next year’s event will take place November 1-3 in St. Louis, Missouri. […]

Read more