I am currently in the process of setting up a local git/development server and have ran into a snag with the gitolite post-hook.

To give an overview of what I am currently doing.

I have setup a local server which contains a 4TB RAID10 being used as a git repository, the machine is also to be used as the local development machine and to streamline the maintenance I am attempting to automate the process of creating Apache Virtualhosts when a new repository is created via gitolite "git-post-init".

I am hoping to accomplish this by cloning the software branch of a repository ( See code below ), adding in the apache vhost config and then symbolically linking it to an apache scanned directory.

The process almost seems to be correct, as I am able to clone the repository add some initial files and create the configuration file but when I attempt to do any git related commands in the repository I am presented with the following error

fatal: Not a git repository: '.'

If I go into the freshly cloned repository after the hook runs I can pull the status of the repository.

git status

Which works ... it just seems that when attempting to do any of this within the hook doesn't.

Below is the code which is being used for the hook with the extra configuration removed to shorten it.


# This will create an apache virtualhost file and store it in the
# repositories conf/reponame.conf directory and then symlink it to
# /home/git/apache/reponame.conf
# A new entry will then be created in the hosts file.

echo "Creating a new X Studios project"
echo "Git Project config v0.1 author Nickolas Whiting: Oct 20, 2011" 

cd $REPO
echo "Cloning repo into $REPO_PATH"
echo "Working in $PWD"
echo "Adding .gitignore file"
touch .gitignore
echo "removed for space" >> .gitignore
git add -u
echo "Commiting changes to repository"
git commit -m "Adding ignore file"
git push
echo "Adding branches"
git branch --track management origin/management
git branch --track design origin/design
git branch --track software origin/software
echo "Commiting new branches"
git add .
git commit -m "Inital Project Setup. Make sure you use the correct branch for what you are doing!"
git push
echo "Checking out the software branch"
git checkout software
echo "Creating Apache Virtualhost configuration"
echo "Removed for space" >> $REPO_PATH/conf/$GL_REPO.conf
echo "Creating symbolic link"
ln -s $REPO_PATH/$GL_REPO.conf $HOME/apache/$GL_REPO.conf
echo "Commiting changes to the repository"
echo "DONE"

I am new to writing bash scripts so if anything is wrong or could be done better please let me know,

Thanks for the help!


If anyone else ever has this problem

Apparently when running inside a gl hook the GIT_DIR variable is set to '.' ( which is apparent ) setting this to the repository .git directory solves the problem


Hope this saves someone the hours I wasted on this!

  • If you found the answer, it is perfectly acceptable to post an answer of your own to this question. You can't accept it until 48 hours after you posted the question, but it lets people know that this was resolved. And importantly, let the system know that it is resolved. – sysadmin1138 Oct 21 '11 at 15:51
  • I will certainly do so after 8 hours since I don't have 100 rep yet. – Nick Oct 21 '11 at 15:53

When running inside a git hook the GIT_DIR variable is set to '.' ( which is apparent ) setting this to the repository .git directory solves the problem


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.