Git is an excellent resource to use for web development as it allows you to streamline live updates in addition to providing a copy of your website files.
For example, you can create your website on your home computer and use Git to push a copy of those files to your DreamHost web server. If anything happens to your home computer, you still have a full copy on the web server. You can then configure this web server repository to push live changes to your website.
Using Git to push live changes to your website
First, follow all steps in the following article:
- Pushing your local Git repository to a DreamHost server — Linux & Mac OS X
- Pushing your local git repository to a DreamHost server — Windows
If you followed all of the steps in that article, your local Git repository on your computer is now copied to your DreamHost server (as a remote repository). But, those changes are just sitting in the remote repository.
If you want your live website to update when you push code to the server, you can add a post-receive hook. This step creates a file to copy updates from your remote server repo to your live site. This example uses a text editor program named nano. View the 'Creating and editing a file via SSH' article for further information on how to edit a file.
- Log into your web server via SSH.
- Make sure you're in your remote repository directory.
[server]$ cd ~/example.com.git
- Open 'nano' and create a file named post-receive:
[server]$ nano hooks/post-receive
- Add this code to the file. It tells where to push these changes. In this example, change shell-username to your actual shell user, change example.com to your website.
#!/bin/sh GIT_WORK_TREE=/home/shell-username/example.com git checkout -f
- Save and close your file to return to your shell.
- Give the file execute rights in the terminal command line:
[server]$ chmod +x hooks/post-receive
Now when you push from your local computer's repository to the server, those changes are automatically added to your live website.