I've setup my environment so I can push to a remote bare repository, I used these commands to setup 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..
The problem: Submodules
I have a few submodules on my project that aren't gettin 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.
I stumbled across this thread two days ago while I struggled with the same issue. After finally arriving at a nice, tidy solution, I wrote an article about it here:
Git push with submodules: a how-to guide
I realized that if I'm going to
push
to a bare repo, only to usepost-receive
topull
into a non-bare repo, I might as well just keep it simple andpush
directly to the non-bare repository. This is a clear case where the "best practice" of only pushing to a bare repo is only adding complexity.In case of link rot, I'll paste my solution here, skipping over the bits where I run into all of the same problems that I'm sure you did.
First, let’s create a universal
post-receive
hook, one that I won’t need to change on a per-repository basis:Now let’s go ahead and break all the rules.
We’re going to initialize a non-bare Git repository, right in our website directory; make sure it can receive from
git push
; explicitly set its working tree to its parent directory; and enable our hook we just created.Finally, on our local machine, we’ll change our remote to reflect the location of our new repository, and push.
Holy crap, it worked!
Not only is this method compatible with submodules, it also requires just one command to set up a new remote repository (which, okay, consists of four commands). It also keeps the repository and the working tree in the same place; and with no absolute paths required in our configuration or hook files, it’s now completely portable as well.
I hope this answer helps somebody as much as everyone else's Stack Exchange posts helped me over the last two days!
One possible way might be:
/var/www/website
as a (non-bare) repopost-receive
hook of your bare repo:GIT_DIR
andGIT_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
I figured out another solution which looks rather clean to me. Just give git all the info it needs to perform the submodule stuff: