Trying to create a git repo that does an automatic checkout everytime someone updates origin

Solution 1:

I'm using a similar hook, but GIT_DIR must point to the .git subdirectory.

#!/bin/sh
cd /home/<user>/<test_repo>
GIT_DIR=.git git pull origin master

Solution 2:

When you set an environment variable, its only available within that shell--so when you launch another program, such as git, the local variables won't get passed along. Lets say we have test.sh:

#!/usr/bin/bash
echo "GIT_DIR=$GIT_DIR"

Now lets look at the following examples

$ GIT_DIR=LOOK_MY_GIT_DIR_IS_SET
$ ./test.sh
GIT_DIR=

This is because the environment variable didn't get exported to the launched program.

$ export GIT_DIR=LOOK_MY_GIT_DIR_IS_SET
$ ./test.sh
GIT_DIR=LOOK_MY_GIT_DIR_IS_SET

In ScottZ's example, setting the environment variable when you launch the program causes it to be exported ONLY for that command.

$ GIT_DIR=LOOK_MY_GIT_DIR_IS_SET ./test.sh
GIT_DIR=LOOK_MY_GIT_DIR_IS_SET

Hope this helps!

Solution 3:

Are you sure you are setting GIT_DIR properly?

I assume you are pulling from a non-bare repo in that case your GIT_DIR should be

GIT_DIR=/home/user/test_repo/.git

To test this run the following on the command line:

GIT_DIR=/home/user/test_repo/.git git status