git Settings hooks hooks

Source: Internet
Author: User

GitHub can be set hooks, see: In the settings webhooks & services , can be Just the push event. set to your server to send a request, and then do the appropriate processing.

Https://help.github.com/articles/creating-webhooks

See document: Man Githooks

NAME
Githooks-hooks used by Git

Synopsis
$GIT _dir/hooks/*

DESCRIPTION
Hooks is little scripts you can place in $GIT _dir/hooks directory to trigger action at certain points. When Git init is run, a handful of example hooks
is copied into the hooks directory of the new repository, but by default they is all disabled. to enable a hooks, rename it by removing it. Sample
Suffix.

Note
IT is also a requirement for a given hooksto be executable. However-in a freshly initialized repository-the. Sample files is executable by
Default.

This document describes the currently defined hooks.

Git hook automatic code for deployment

Assuming your project is also running on this server, the automatic deployment of the code is simple, such as your online service code in the/var/www/demo folder.

/var/www/demo must have write permission, too.

You first initialize the code base:

clone /opt/git/gitdemo /var/www/demo

Then you can git pull update the code by going to it.

Of course this is manual, I want to be the local commit update, the server can automatically git pull code to the latest, so we need to use git hook .

Enter into the/opt/git/gitdemo folder, you will find the. Git/hook folder inside, into the hook, there are a lot of sample script, here we only need to use the post-update.

$ mv post-update.sample post-update $ vim post-update

You can see that there are actually some shell scripts in it, and all you have to do is write Git pull. When the user commits, the post-update script is called.

For example, after I update the code base of the server, I require the corresponding service code to be updated (pull operation).
In the bare warehouse hooks post-receive Add the following content

#!/bin/sh unset $(git rev-parse --local-env-vars)cd WEB_DIRgit pull

These scripts obviously can do a lot of things, as long as you want to know when each script is called, Google Bar.

Note: folders and files in the server that are related to git users

$ CHOWN-RH Git:git/your/git/dirs

In addition article:

Best tool git Hook

Post-update.sample renamed to Post-update

Then add a few simple lines of code to get your needs up.

Cases:

gitdir=/****

CD $gitdir

git checkout corresponding Branch

Git pull

End ...

git Settings hooks hooks

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.