A lightweight tool to manage WordPress projects with Git, enabling seamless database syncing and environment sharing without relying on heavy migration plugins.
- Environment Variables: Create a
.envfile in thewp-gitdirectory (you can copy.env_example). Fill it with your local database credentials:DB_HOST=localhost DB_NAME=your_db_name DB_USER=root DB_PASS=root DB_PORT=3306
- WP-CLI: Ensure
wp.pharis located inside thewp-gitdirectory. This is required for automatic domain search-and-replace during imports.
You no longer need to worry about manually adding PHP or MySQL/mysqldump to your system PATH! WP-Git now includes intelligent wrapper scripts that automatically detect paths from common local development tools (Local WP, XAMPP, Laragon, and MAMP) and execute the commands for you.
All scripts must be executed from the terminal/command line (CLI) in the root of your WordPress project.
For Windows (CMD):
Use wp-git\export or wp-git\import
For Windows (PowerShell):
Use .\wp-git\export or .\wp-git\import
For Mac/Linux (Bash):
Use wp-git/export or wp-git/import
Before you commit and push your work to GitHub, run this command to export your current database:
Windows (CMD):
wp-git\exportMac/Linux/Git Bash:
wp-git/exportWhat it does: Exports a dump to db/latest.sql (which is tracked by git) and keeps local rolling backups in db/backup/ (which are ignored by git).
When you pull new changes from GitHub, or if you just cloned the project, run this command to load the database:
Windows (CMD):
wp-git\importMac/Linux/Git Bash:
wp-git/importWhat it does: Imports db/latest.sql into your local MySQL database and automatically runs a search-and-replace to ensure the URLs match your local environment.
To update these core scripts from the main GitHub repository, you can call the main script:
Windows:
wp-git\wp-git.bat upgradeMac/Linux:
wp-git/wp-git.sh upgradeIf a developer wants to clone this WordPress repository and get it running locally, they should follow these steps:
-
Clone the repo:
git clone <your-repo-url> -
Create local environment: Point your local server (LocalWP, XAMPP, Docker) to the cloned directory.
-
Configure WP: Copy
wp-config-sample.phptowp-config.phpand configure it with your local database details. -
Configure WP-Git: Copy
wp-git/.env_exampletowp-git/.envand add those same local database credentials. -
Create Database: Ensure an empty database exists in your local MySQL instance.
-
Enable Aliases: Open your terminal in the project root and run the setup script once:
Windows (CMD):
wp-git\setup.bat
Mac/Linux:
./wp-git/setup.sh
-
Import & Sync: You can now run the import script from any directory inside the project!
git import
-
🎉 The database will be imported, URLs automatically updated, and the site will be fully operational on your local machine!