Git Hook Sync Server code

Source: Internet
Author: User

Reference and reprint from:

http://www.embbnux.com/2014/09/05/git_server_let_code_auto_deploy/

Http://www.chenyudong.com/archives/git-sync-manage-website.html#i

1. Create a remote repository

$ mkdir/home/www.cnblogs.com/www.cnblogs.com.git #将来网站git的记录存放位置 $ chown-r git:git www.cnblogs.com.git #改权限 $ cd www.cnblogs.com.git$ git init--bareinitialized empty git repository in/home/www.cnblogs.com/www.cnblogs.com.git/

2. Create a new post-receive file in the hooks directory of the Git remote repository:

#!/bin/sh #author: Embbnux#blog of embbnux:http://www.embbnux.com #判断是不是远端仓库IS_BARE =$ (git rev-parse-- is-bare-repository) If [-Z] $IS _bare "]; Thenecho >&2 "Fatal:post-receive:is_not_bare" Exit 1fi unset git_dirdeploypath= "/var/web" echo "=============== ================================ "CD $DeployPathecho" Deploying the Test Web "git fetch--allgit reset--hard origin/maste R time= ' Date ' echo Web server webserver at time: $time. " echo "================================================"

Grant executable permissions after saving:

chmod +x hooks/post-receive

  

Git Hook Sync Server code

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.