The Ultimate Guide To Automatic Updates With WP Pusher

Push-to-Deploy is the feature of WP Pusher that will keep your WordPress websites up-to-date every time you push some fresh code to your Git repositories. In this post, we are going to take a look at what Push-to-Deploy is, how best to use it for an effective workflow.

[content_upgrade cu_id=”652″]Get the bonus video: A Solid Deployment Strategy With WP Pusher[content_upgrade_button]Watch it now[/content_upgrade_button][/content_upgrade]

What is Push-to-Deploy

Push-to-Deploy is the flagship feature of WP Pusher. When enabled, it will make sure that your WordPress websites always stays up-to-date with your Git repositories. If you installed a plugin or theme with WP Pusher and enabled Push-to-Deploy, whenever you push fresh code to GitHub or Bitbucket, your sites will be updated.

Push-to-Deploy is one of those features that should probably be labeled with a “use with care” sticker, since it’s quite powerful. Later in this post we’ll talk about when and where to use it.

The magic of webhooks

WP Pusher is possible because of something called webhooks that GitHub and Bitbucket offers. A webhook is simply an HTTP request that will be fired when various events occur. When using GitHub or Bitbucket, you get to configure which URLs to ping when a webhook is fired. For example, with WP Pusher there’s a unique URL for each plugin and theme called the Push-to-Deploy URL. Whenever this URL gets hit, WP Pusher will deploy the latest version of said theme or plugin. When you enable Push-to-Deploy for a theme or plugin, WP Pusher will tell GitHub or Bitbucket to hit that specific URL every time new code is pushed to the repository.

If you are curious to see this in action, you can check out the webhooks area for a repository on GitHub or Bitbucket:

On GitHub, you can see all the times a webhook was fired.

On GitHub, you can see all the times a webhook was fired.

You will be able to see exactly how the webhook HTTP request looked and what kind of response it got:

Webhook details on GitHub

By clicking on a webhook, you can see the payload sent and all the HTTP information you need for debugging purposes.

If a webhook results in a successful update of a theme or plugin, WP Pusher will make sure to return a 200 status code.

Setting up Push-to-Deploy with WP Pusher is very simple. Since we go through the Bitbucket and GitHub APIs to do this, you need to make sure that you have a valid token stored. Since version 2.1.0 of WP Pusher, getting a token is very simple. Just click the “Obtain a Bitbucket/GitHub token” button, copy and paste the token and save it in WP Pusher.

Add Bitbucket token in WP Pusher

It’s super easy to obtain a secure token for GitHub or Bitbucket with WP Pusher. Just click the button, copy and paste the token and store it in WP Pusher.

Once you have a valid token stored, all you need to do is check the “Push-to-Deploy” checkbox on the plugin/theme installation page. WP Pusher will then take care of all the details of setting up the necessary webhook on GitHub or Bitbucket.

Enable automatic Git updates for WordPress with WP Pusher

WP Pusher will take care of all the webhook magic needed to set up automatic updates. Just tick the Push-to-Deploy box and WP Pusher will set up everything needed on GitHub or Bitbucket.

When and where to enable automatic updates

As mentioned already, Push-to-Deploy is one of those features that should probably be labeled with a “use with care” sticker, since it’s quite powerful. Imagine if you enable Push-to-Deploy for a production website and accidentally push a bug to your Git repository. WP Pusher will then go ahead and deploy the buggy code and your production website will be broken. Generally, there are 2 ways to avoid this happening:

The first option is to not enable Push-to-Deploy in production. Simply enable it for your staging site (because surely you have one, right!) and then manually click the “Update plugin/theme” button within WP Pusher for the production website, when you are ready to deploy.

This first option is a bit of a downer, if you were counting on WP Pusher to do all the hard work of updating your websites. Here’s the setup I recommend instead:

First of all, you need 2 branches for this setup to work: A development branch and a master/production branch. While you work on a new version of your theme or plugin, you commit everything to your development branch. This is also the branch that’s deployed to your staging site – with Push-to-Deploy enabled. On the staging site you can test that everything works as expected in a realistic environment. When a new version is ready to be released to production, your merge your development branch with your master branch, which is deployed to your production site(s). With this setup, it’s safe to setup Push-to-Deploy on your production site, since the master branch will only be updated once you choose to merge the development branch. If you want to learn more about what branches and merging means, feel free to sign up for my free video course on Git for WordPress developers.

[content_upgrade cu_id=”652″]Get the bonus video: A Solid Deployment Strategy With WP Pusher[content_upgrade_button]Watch it now[/content_upgrade_button][/content_upgrade]

Thanks for reading this far. I’d love to hear more about your current deployment setup – just post a comment below!

 

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.

 
  • Cameron Jones

    I’ve found it to be super helpful using dev and production branches in my plugin development. And then a third branch to address a particular ticket. Git just makes things so easy

    • Peter Suhm

      Yeah, that’s a great way to do it. Branch for each release and then issue/feature branches for each thing you’re working on!