If there was a way to streamline your code backup, development, and deployment would you do it? Git is a solid solution, but benefits from some fine tuning to improve WordPress development.

Starting from Scratch

If you’re unfamiliar with Git download the Github desktop app to get started. Github has a quick start guide to get up and running, which is all you’ll need for this post. If you’d like to go more in depth there’s a free course at CodeCademy which takes a couple hours to complete.

Why use Git for WordPress development?

  • Automatic backup of your code
  • Easy method to undo changes
  • View changes across your commits (useful when clients want something how it was 3 months ago)
  • Work on bug fixes, and new features, and with others without interfering with your existing (working) code with branches

Ignoring Non-essential Files

If you commit the entire WordPress install to your repository you end up with a lot of fluff that could trip you up later. If you need to roll back a change, but that specific commit was bundled with a WordPress update where some core files got changed, rolling back would affect your WordPress installation. This also affects the install of anyone else working on the same code.

Ideally you would only commit the files you’re actively working on such as custom themes and plugins. You can tell Git to only look at your custom themes and plugins with a .gitignore file placed at the root of your project folder. A good starting point might look something like:

# Ignore everything in the root except the "wp-content" directory
/*
!.gitignore
!wp-content/

# Favicons should be included
!android-chrome-*.png
!apple-touch-icon-*.png
!browserconfig.xml
!favicon.ico
!favicon-*.png
!manifest.json
!mstile-*.png
!safari-pinned-tab.svg

# Ignore everything in the "wp-content" directory, except the "plugins" and "themes" directories
wp-content/*
!wp-content/mu-plugins/
!wp-content/plugins/
!wp-content/themes/

# Ignore everything in the "plugins" directory, except the plugins you created
wp-content/plugins/*
!wp-content/plugins/my-plugin-1
!wp-content/plugins/my-plugin-2

# Ignore everything in the "themes" directory, except the themes you created
wp-content/themes/*
!wp-content/themes/my-theme