Post-receive hooks in git system do not perform git pull solution correctly

Source: Internet
Author: User
Tags git hooks

One requirement is for local git to automatically perform git pull under/dir/foo on a remote server after the push to a remote git repo. It's a very simple requirement to add a post-receive hook to the hook in the remote Foo.git warehouse and add a git pull to the hooks. But the actual operation of the time to find a problem, because this ignores a small detail of the problem.

Before you do so, the code in your head is as follows:

#!/bin/sh
Cd/var/git/web3/etc/puppet
/usr/bin/git Pull

With this code, after git push ssh://git@ownlinux.org:/opt/foo.git, it is found that the/dir/foo directory on the remote server does not successfully pull to the most recent data, and there are also errors on the terminal (remote:fatal: Not a git repository: '. ' )。 Later, the git hooks are found to invoke GIT_DIR this environment variable instead of PWD this. So when git pull, it prompts not a git repository: '. ', where "." is git_dir the value of this environment variable.

After the code for the hook is changed to the following, it works:

#!/bin/sh
Unset $ (git rev-parse--local-env-vars)
Cd/var/git/web3/etc/puppet
/usr/bin/git Pull

Friends who use Git to version control hope you don't ignore this little detail as much as I do.

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.