* * Use Git hooks for automated site deployment

Source: Internet
Author: User
Tags using git git hooks

Http://www.tuicool.com/articles/3QRB7jU

Automation can liberate the human hands, and more importantly, because the prescribed process to walk, but also reduce the production of many misoperation. Do not know how you usually update their own production environment code, FTP overwrite old files, server scheduled task to build the latest source, or there is more advanced practice?

I'm currently using a Git Hook to deploy my project. A git hook is a hook provided by git that can be invoked after a specific event is triggered. In fact, more generally speaking, when you set up a git hook, as long as your remote warehouse received a push, Git hook can help you execute a bash script.

Here are my simple automated deployments using Git hooks, and there may be more advanced practices that you can dig for yourself.

Initializing a remote Git repository on the server

git initand git --bare init The original warehouse is completely different, specific I Google, English is understood, but to translate the Chinese but do not know what adjectives to call these 2 kinds of warehouses.

Here we're going to git --bare init initialize a remote repository by initializing

$ cd ~$ mkdir testRepo$ cd testRepo$ git --bare init
Initializing a local Git repository on the server

This repository is initialized by the git init most common local repository, its role is to pull the remote repository (in fact, next to it) the latest source code, and then compile in this warehouse, the code compiled to the WWW directory (the root directory of the Web site).

$ cd ~$ mkdir testDeploy$ cd testDeploy$ git clone ~/testRepo #从远程仓库 clone 出源码
Set up hooks for remote warehouses
$ cd ~/testRepo/hooks$ vim post-receive

post-receiveThe execution script inside

#!/bin/shunset git_dirdeploypathwwwpath=/home/wwwroot/testdeploy< Span class= "line" >CD  $DeployPath Span class= "line" >git Add. -A && git stashgit pull Origin master # the following 2 steps are all based on the actual bash script you added  $WwwPath # I used the FIS to compile the front-end code qrsync/home/user/qiniutools/config.json # sync with seven kn sync tool  

Finally, to post-receive add executable permissions

chmod +x post-receive
Add a remote source to a local warehouse

This time the local warehouse is really your development machine above the local. Add a new remote source to your existing Git project, and the push code in the remote source will automatically trigger the bash script above.

$ git remote add deploy user@server.ip:/home/user/testRepo$ git push deploy master

* * Use Git hooks for automated site deployment

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.