Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I got a GIT repository with a couple of submodules. Now i created a "post-update" hook on my webserver that automatically deploys my website on update.

That's how my post-update hook looks like:

rm -rf /home/my_user/public_html/my_website/*
export GIT_WORK_TREE=/home/my_user/public_html/my_website/
export GIT_DIR=/home/my_user/gitrepos/my_website.git
git checkout -f

Everything works nicely apart from the fact that the submodules directories are not exported... And that is my question. How can I deploy a GIT repository and it's submodules through the post-update hook?

Thanks in advance!

share|improve this question

It should work, except you could add, for taking care of those submodules:

git submodule init
git submodule update

See also Using git submodule update --init on a post hook if you have error messages.

share|improve this answer
up vote 1 down vote accepted

Alright I made a script that avoids the use of a non-bare repository and receive.denyCurrentBranch ignore



unset GIT_DIR

# Recreate HTTP dir
rm -rf $DIR_HTTP
mkdir $DIR_HTTP

# Clone git repository
git clone $DIR_GIT $DIR_HTTP

# import submodules
git init --bare $DIR_HTTP
git submodule init
git submodule update

# delete unnecessary git repository in http dir
rm -rf $DIR_HTTP/.git

Any improvements are welcome

share|improve this answer
Nice feedback, more practical than my own answer. +1 – VonC Jan 3 '13 at 19:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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