Demystifying Git For WordPress Developers

The WordPress world, once dominated by Subversion, mainly due to the infrastructure of WordPress.org, is slowly moving towards using Git. This is great news, but for many developers Git can seem strange or even intimidating. In this post I will do my best to demystify Git for WordPress developers.

1. Git Is Decentralised

If as a WordPress developer you are used to working with Subversion (SVN), the biggest conceptual difference you have to understand is that Git is decentralised. There is no WordPress.org, central repository where everything is stored. Git was built to be a distributed tool. In Git everything is stored locally on your own machine. Yes, you can push your repository up to a host like GitHub.com, but it won’t be anything else than a copy of what you have locally.

A Git repository is just a bunch of files added in a hidden folder in your project named /.git. This folder contains everything. Every commit, branch and code change someone ever made is referenced in this folder. Note the word referenced. We will talk about this in the next paragraph. Because every developer has a full copy of the code locally, it is critical that you have determined a workflow that you all follow in order to keep code in sync. If you are more than one developer, every developer should probably work on his or hers own branch to avoid too many merge conflicts. Oh yeah, there is another benefit of keeping everything locally until you choose to push it: You can completely modify your commit history (i.e. overwrite and hide all the mistakes you made!).

2. Git Is Lightweight

Git only stores the changes you made, so files that have no changes are not duplicated. This means that, unlike SVN, branching out is very lightweight. When creating a new branch in SVN, in essence, you are just creating a new directory in the /branches folder with a copy of the code.

3. Git Is Not Subversion

There are a few differences between Git and SVN that I have heard people confuse many times. Here are 3 of them:

  • A repository
    • Git: Nothing more than what is in your local /.git folder
    • SVN: A single central code repository on a server
  • Checking out
    • Git: Switch to a different reference in the history (typically a branch or commit)
    • SVN: Download (part of the) code from the central server in order to work on it (quite similar to Git’s clone)
  • A branch
    • Git: Literally a branch of the working tree with a full history of all changes (since forever)
    • SVN: A folder in the /branches folder ( and /trunk is conceptually similar to master in Git)

4. Git Is Not A Backup Tool For Your Blog

No, it is not! No, I will not hear it! It is not!

Git is awesome for code versioning. That is your code. Managing 3rd party code with your own version control system (VCS) hardly ever makes sense and makes keeping things up-to-date a pain. Managing your whole WordPress blog, including user generated content, with a VCS is wrong. There are great tools that can back up WordPress and you should be using them. But use Git for what it is great at. Managing code revisions.

5. Git Has An Awesome Ecosystem

The title of this section should probably have been “GitHub Is Amazing”.

The fact that using Git as your VCS allows you to use GitHub (and Bitbucket) should be reason enough to make the change. These tools makes collaboration a breeze once you get familiar with them. The way GitHub has tackled merging code with pull requests (PRs) is truly awesome.

Also, everyone uses Git nowadays!

Where To Go From Here

If you want to learn more about Git, here are a few links to some in-depth resources I recommend:

 

Want to read more like this?

Add your email address below to stay in the loop when new content arrives. You'll never miss a post.

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.