GIT uses hooks to push directly to the working directory

Source: Internet
Author: User

Remote machine

$ MKDIR/WWW/TEACHERAPI # Create working directory

$ cd/data/git

$ git init teacherapi.git--bare--shared

Initialized empty shared Git repository in/data/git/teacherapi.git/

$ CD teacherapi.git/

$ vi hooks/post-receive # or use cat > hooks/post-receive to create and type the following code, and finally Ctrl+d save the exit,

#!/bin/sh

Git_work_tree=/www/teacherapi git checkout-f <branch> # default Master Branch

$ chmod +x hooks/post-receive # Set executable permissions

You can also use the following code snippet

$ cd git

$ mkdir Somesite.git

$ CD somesite.git/

$ git init--bare

Initialized Empty Git repository in/home/caius/git/somesite.git/

$ git--bare update-server-info

$ git config core.worktree/home/caius/vhosts/somesite.com/htdocs

$ git config core.bare false

$ git config receive.denycurrentbranch ignore

$ cat > Hooks/post-receive

#!/bin/sh

Git checkout-f

^d

$ chmod +x hooks/post-receive

Execute script after work tree update is complete

$ cd/gitpah/hooks/

$ VI post-checkout #创建post-checkout Type the following code, and when the ' git-checkout ' command finishes updating the entire work tree (worktree), the hook is called

#!/bin/sh

/etc/init.d/teacherapitest.tbkt.cn restart

$ chmod +x post-checkout

Local Machine

$ git clone ssh://[email protected]:6022/data/git/teacherapi.git

$ CD teacherapi/

$ Echo ' Hello, world! ' > index.html

$ git add index.html

$ git commit-m "init project"

$ GIT push origin Master:master

Add a remote repository

$ git remote add 106 ssh://[email Protected]:6022/opt/gitdata/chsy_cms.git

Error during remote push: cannot run hooks/post-receive:no such file or directory

In addition to checking the contents of the Post-receive file, also look at the file format right, using the $ cat-a hook/post-receive view

Document Content Reference:

Http://caiustheory.com/automatically-deploying-website-from-remote-git-repository

Http://toroid.org/ams/git-website-howto

More Hooks Usage: http://www.360doc.com/content/12/1012/11/10140166_241004726.shtml

GIT uses hooks to push directly to the working directory

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.