I've setup my environment so I can push to a remote bare repository. I used these commands to set up the remote repository:
$ mkdir ~/website.git && cd ~/website.git
$ git init --bare
And
$ cat > hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=/var/www/website git checkout -f
$ chmod +x hooks/post-receive
And on my local environment:
$ git remote add web ssh://website.com/home/website.git
$ git push web +master:refs/heads/master
Now I can deploy to this remote using git push web
, and everything works great..
I have a few submodules on my project that aren't getting initialized/updated at the remote repository. I can't run git submodule update
on the bare because it's bare, and I can't run it on the /var/www/website
folder because it's just a copy of the files and not a git repo.
One possible way might be:
/var/www/website
as a (non-bare) repopost-receive
hook of your bare repo:
GIT_DIR
and GIT_WORK_TREE
to the non-bare repo at /var/www/website
cd /var/ww/website
git pull ~/website
git submodule update
(a bit like in "How do I init/update a git submodule in a working tree after pushing to a bare working directory?")In other words:
Pull from the bare repo instead of trying to checkout from a bare repo: a non-bare repo should be able then to accommodate the git submodule update
step.
An example script may look like
#!/bin/sh
# Get the latest code
cd /path/to/bare/repo
# Set git variables
GIT_WORK_TREE=/var/www/website
GIT_DIR=/var/www/website/.git
# Go to website and pull
cd /var/www/website
git pull /path/to/bare/repo
git submodule update --init --recursive
# Run additional build stuff here