How to use WP-CLI with VersionPress

Updated on Dec 6, 2022

VersionPress comes with several WP-CLI commands for more advanced users and those who prefer to do things via the command line. WP-CLI is available on all of our Shared Hosting Servers always up to date as new WordPress versions also require the latest WP-CLI version.

To use WP-CLI with VersionPress, you will need to navigate to the root of your website and execute the appropriate commands there. If VersionPress is not activated you will need to use --require to execute a specific WP-CLI command.

If you need guidance, you can always use wp help for the latest available commands.

vp config - Configures VersionPress. For more information on the configuration, you can check the official documentation configuration.

vp undo - Undo a commit.

This does the same as clicking the Undo this button in the admin area. In case there is a conflict with a commit, the same rules as the ones explained in the Undo and Rollback tutorial apply.

In order to get the commit as an argument you will need to also execute

git log

and copy the SHA1 b236229495a54a3b10bb7113b0fbd8ce392fcc2b or the first 7 characters of it.

Using the WP-CLI command git log

wp vp rollback b236229

Using the WP-CLI command wp vp undo

If you have uncommitted changes on your website, you will receive the following error.

Using the WP-CLI command wp vp undo with uncommited changes

vp rollback - Reverts site to a previous state.

It is the same action as clicking the Roll back to this button in the admin screen.

wp vp rollback b236229

Using the WP-CLI command wp vp rollback

vp restore-site - Restores site from a Git repository.

You will typically use this command when you want to restore the database after something has broken it. Alternatively you can always use the last daily backup if the time period passed corresponds to your needs.

If you have completely removed your database wp vp restore-site will re-create the database tables much like a restore from a backup would work.

You will have to include the --require=... parameter because WP-CLI will not be able to detect the vp command on its own.

wp vp restore-site --siteurl='http://localhost/mysite' --require=wp-content/plugins/versionpress/src/Cli/vp.php

vp clone - Clone the site to a new folder, database and Git branch.

vp pull - Pulls changes from another site instance and creates a merge if there is need for such.

vp push - Pushes changes to another site instance. Does not create a merge.

vp apply-changes - Applies changes found on the disk to the database which is particularly useful after resolving a merge conflict.

How to use the WP-CLI command wp vp apply-changes

vp check-requirements

With this command, you can check if all of the requirements for using VersionPress are met on the environment you wish to use it. All Shared Hosting FastComet servers meet the requirements for VersionPress, so you will need to use this only if you are using external resources.

If you are having issues with the execution add the —require= parameter.

We hope this tutorial will prove helpful to those advanced users who decide to use WP-CLI in order to manage their VersionPress functionality.

On this page...

    WordPress Hosting

    • Free WordPress Installation
    • 24/7 WordPress Support
    • Free Domain Transfer
    • Hack-free Protection
    • Fast SSD Storage
    • Free WordPress Transfer
    • Free CloudFlare CDN
    • Immediate Activation
    View More