Super simple way to develop locally and then deploy sites via GitHub.
This screencast was inspired by Mark Otto’s great post about this workflow. Implementing this workflow takes next to no time, is very easy to upkeep and is also secure for your files thanks to GitHub.
Running time: 9:14
Commands to Clone and Maintain
Once you have committed your code to GitHub you can follow these steps to quickly deploy.
$ ssh username@website.com
Once connected, navigate to your domain and clone the repository in the desired location.
$ git clone [REPO_URL]
Once you have completed the above, all future updates just need to be done like so:
$ ssh username@website.com
Once connected, navigate to your repository (make sure you are inside the repository!).
$ git pull origin master
Reload your live site.
Note: You might have to install Git on your server.
Happy deploying!
You can set GitHub to automatically tell your website that a commit has been pushed to your repository. If you go into
[Your Repo] -> Settings -> Service Hooks -> WebHook URLs
and enter the url to a PHP file on your site, GitHub will make a POST request letting you know a push has been made.Here’s how I would do it.
Create a “secret” PHP file at the root of your domain called update-theme.4b48af.php with the following content.
<?php
// tell our shell script to update the theme
`./update-theme.sh`
Inside the shell script update-theme.sh
Note: you may need to call
chmod +x update-theme.sh
to make it executable.# change to the theme directory and
# pull the changes from GitHub
cd ./wp-content/themes/wp-weekly-theme && git pull origin master
The shell script is just a series of bash commands. I used the
&&
so that the second command would only run if it changed to the proper directory.Also, I separated the bash commands from the PHP because it makes more since running bash commands from a shell script.
PS: I’m not sure how the code will look in this comment, so I created a GitHub Gist to be careful: http://git.io/xG98oA
Baylor!
That is awesome, I didn’t realise how easy it is. I haven’t had time to set it up yet but will soon.
BTW – You have some awesome vids on your YouTube channel. Keep them coming.
Thanks again.
A while back I built the base functionality into a Rakefile. Check it out here: https://gist.github.com/2243053
Hopefully someone will find it helpful. Just put it in the root of your project, add in the config details and you can run `rake deploy[env,branch] ` from the command line.
Enjoy!
Oh thats pretty sweet Matt!
I am sure it won’t be just me that will find that handy. Thanks for sharing.
This is how we do it for ArcTap. We have a file in the root of the project called
github.php
which has the following contents…<?php `git pull`;
This workflow was suggested from this article and is pretty easy to setup.
There is also another method Paul Irish mentions in his talk at the HTML5DevConf and starts at 13:00.