Git is a powerful version control system that allows you to track changes to your codebase and collaborate with other developers. WP-CLI is a powerful command-line interface for managing WordPress installations. Combining the power of Git and WP-CLI can make managing WordPress projects a breeze. In this article, we’ll show you how to use WP-CLI with Git to manage your WordPress projects.
Getting Started

Before we dive into using WP-CLI with Git, let’s make sure you have Git and WP-CLI installed and ready to go. If you don’t have them installed, please refer to the “Install Git the easy way” and “Installing WP CLI” articles.
Creating a Git Repository
The first step in using Git with WP-CLI is to create a Git repository for your WordPress project. Here’s how to do it:
- Navigate to your WordPress project directory using the command line.
- Initialize a new Git repository using the following command:
git init
- Add all files to the repository using the following command:
git add .
- Commit the files using the following command:
git commit -m "Initial commit"
Installing WordPress with WP-CLI
Now that you have a Git repository for your WordPress project, you can use WP-CLI to install WordPress. Here’s how to do it:
- Navigate to your WordPress project directory using the command line.
- Run the following command to install WordPress:
wp core download --locale=en_US
This command will download the latest version of WordPress in English. - Run the following command to create a wp-config.php file:
wp config create --dbname=database_name --dbuser=database_user --dbpass=database_password
Replace “database_name”, “database_user”, and “database_password” with your database details. - Run the following command to install WordPress:c
wp core install --url=example.com --title="My WordPress Site" --admin_user=admin --admin_password=password [email protected]
Replace “example.com”, “My WordPress Site”, “admin”, “password”, and “[email protected]” with your site details.
Adding Changes to Git
Now that you have installed WordPress with WP-CLI, you can add the changes to Git. Here’s how to do it:
- Navigate to your WordPress project directory using the command line.
- Run the following command to see the changes that have been made:
git status
- Run the following command to add the changes to Git:
git add .
- Commit the changes using the following command:
git commit -m "Installed WordPress"
[…] If you are using Git to manage your WordPress website, you can use WP CLI to simplify your workflow. You can use WP CLI to perform various Git-related tasks, such as committing changes, pushing changes, and more. Check out our full article here. […]