Use GIT instead of FTP deployment code to the server example _ related tips

Source: Internet
Author: User

When local development is complete, it is usually deployed on the server, someone will use FTP, some people will use the SCP, FTP and SCP to facilitate our adoption and also to tar or zip, these practices are also good, but it has some problems

1. All updates, no matter whether some files are modified, to retransmit the server, waste of time and traffic
2. Multiple server repeat upload
3. After the code update, some of the subsequent operations are not automated

The above problem can be solved by direct remote execution via SSH, but need to write some shell scripts, is there a simpler and more efficient way? Yes, that's the hook! of using version management tools.

Here I say is version management tools rather than git, because SVN, Git, Hg are the corresponding hooks, the principle is similar. Here's a detailed idea of git.

Server-side operations

First create a naked library, why is the naked library? Because this library is not really used for modification, we do not allow the code to be modified on the server, we just use it as a place for code transfer:

Copy Code code as follows:

CD Gitroot
mkdir ProjectName
CD ProjectName
Git init--bare

Add our Hooks

Copy Code code as follows:

Cd/hooks
Touch post-receive

Edit Post-receive content for the following, where Sites/projectname is where we store the site code
Copy Code code as follows:

Env-i Git archive Master | Tar-x-c/sites/projectname
echo "Remote Update Complete"

Actions for local git

Local we just need to add a remote library, the need to deploy to push to the remote library on the line, we have added a remote library named publish

Copy Code code as follows:

Git remote add publish Username@xx.xx.xx.xx:/home/gitroot/projectname
git push publish Master

Where it can be fortified.

Here demo is a simple small web site deployment process, complex circumstances we can also add static resource version update, server restart and so on, extrapolate, maximum program automation of our work.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.