2

Using Git for web development

 3 years ago
source link: https://help.dreamhost.com/hc/en-us/articles/115000684492-Using-Git-for-web-development
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Using Git for web development

Overview

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:

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.

  1. Log into your web server via SSH.
  2. Make sure you're in your remote repository directory.
    [server]$ cd ~/example.com.git
  3. Run nano and create a file named post-receive:
    [server]$ nano hooks/post-receive
  4. Add this code to the file. It tells where to push these changes. In this example, change username to your actual shell user, change example.com to your website.
    #!/bin/sh
    GIT_WORK_TREE=/home/username/example.com git checkout -f
  5. Save and close your file to return to your shell.
  6. Give the file execute rights.
    [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.

See also

Did this article answer your questions?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK