Home » Wordpress » How can I deploy a WordPress site with Git without committing WP core?

How can I deploy a WordPress site with Git without committing WP core?

Posted by: admin November 30, 2017 Leave a comment


I’ve been researching how to use git for WordPress deployment. Nearly all of the examples have WordPress as a remote repository that is merged into master/feature branch regularly.

I don’t want to commit the WordPress core into my repository. I basically want to ignore everything except the files I’ll be changing (mainly my custom theme). Is there a simple way I can do this, but still keep a local, staging and production server running the same WordPress version?


Merging the remote repository isn’t necessary unless you want changes from upstream in your copy.

Suppose you have your WordPress locally in a folder called wp and it isn’t already a git repo:

cd wp
git init .
touch .gitignore # Add required stuff to .gitignore.
git add .
git commit -m "Initial commit."

Now when you want to reflect these changes remotely just push to the remote of your production or staging servers.

git push staging master

Possible Solution via git Submodules

Say you have your WordPress setup on github. First clone the repo:

git clone git://github.com/Soliah/Wordpress.git
cd WordPress
git checkout origin/3.2-branch

Now say you have a theme “awesomeness”:

cd WordPress
git submodule add https://github.com/Soliah/awesomeness.git ./wp-content/themes/awesomeness
git submodule init
git submodule update

Now anytime you want to update your theme first update the theme repo:

cd awesomeness
# update some stuff
git add .
git commit -m "Update theme."
git push origin master

Back in wordpress just update the submodule and push to github.

cd WordPress
git submodule update
git commit -m "Update theme submodules."
git push origin master

On your other servers you can either git clone git://github.com/Soliah/Wordpress.git && git submodule update --init or git pull if they’re already present.