Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git post-receive not working correctly

I have the following problem. I have updated the 'post-receive' to cd into a certain directory and then pull the repo in to deploy it like so:

#!/bin/bash
cd /var/www/site
git pull origin master

However whenever I do 'git push origin master' on my local machine I get the following:

Counting objects: 5, done.
Delta compression using up to 2  threads.
(etc..)
remote: fatal: Not a git repository: '.'

Yet when I manually cd to /var/www/site and do git pull origin master it works brilliantly.

like image 542
andy Avatar asked Mar 28 '12 10:03

andy


People also ask

How githooks work?

Git hooks are scripts that run automatically every time a particular event occurs in a Git repository. They let you customize Git's internal behavior and trigger customizable actions at key points in the development life cycle.

Are Git hooks files version controlled?

As mentioned above, client-side hooks are local to any given Git repository. This means they are not cloned with the rest of the project and are not version-controlled. As such, maintaining hooks for a team can be tricky. One workaround is to store the hooks in the project directory, above the .

How to use pre-commit hook?

If you want to manually run all pre-commit hooks on a repository, run pre-commit run --all-files . To run individual hooks use pre-commit run <hook_id> . The first time pre-commit runs on a file it will automatically download, install, and run the hook. Note that running a hook for the first time may be slow.

How to add pre-commit Git hook?

Open a terminal window by using option + T in GitKraken Client. Once the terminal windows is open, change directory to . git/hooks . Then use the command chmod +x pre-commit to make the pre-commit file executable.


1 Answers

Use unset GIT_DIR as following

#!/bin/bash
cd /var/www/site || exit
unset GIT_DIR
git pull origin master
exec git-update-server-info

You can see more information about GIT_DIR here. Git Loves the Environment

like image 67
Hasintha Janka Avatar answered Oct 19 '22 03:10

Hasintha Janka