If you’re still deploying and updating sites with FTP or by generally pushing files around, here’s an easier way—deploy with Git!
The basic principle is to use
git pull origin master on your production server to pull down the latest version and it helps to maintain multiple branches (at least
master for production and
dev for development) or even use Feature Branching for more control.
Your development workflow could be:
git pull origin dev && git checkout devto get latest development branch and switch to it
- Do your work
git add whatever.phpto stage changed files
git commit -m 'Did something'to commit your changes
git push origin devto push changes to the server
git checkout master && git merge devto switch to master and merge your work
Then you just need to SSH to your production server,
cd into the site and
git pull origin master to handle the process of actually updating the files.
Git manages your versioning, so you can use it to roll-back. Before you deploy, get the hash for the current version (e.g.
694d0ea280) so that if you need to roll-back you can just run
git checkout 694d0ea280.
Knowing you can safely and efficiently roll-back is a huge advantage, especially when you know how exactly how to do it before you ever need to!
Deploying a WordPress Plugin or Theme with Git is a little more tricky, because if someone visits the site when the folder name has changed (while making the switch between the static folder and the git repo) the plugin/theme will be deactivated, potentially losing your configuration and giving as visitor a bad experience.
On a corporate production site, for example, reverting to the Twenty Fourteen theme just isn’t acceptable!
The trick is to make the switch in one command, so if the theme folder is called “my-theme” and the repo is called “my-theme-repo”, clone the repo in WordPress’s themes directory, then run
mv my-theme my-theme-old && mv my-theme-repo my-theme so the old theme is renamed to “my-theme-old” and the repository takes its place.
Now you can deploy by
cding into the theme directory and following the workflow above.