Q:

Git post-receive hook and environment variables

I have git server running on Gitolite, under "git" system user. I added to ~/.profile of git user: export STAGE_PATH="/srv/http/stage" , as you can guess, I want to automagically put website from repo on stage when pushing changes. However it seems that variable STAGE_PATH is unavailable to me in post-receive hook. Is it normal? Is there a way to access environment variables from post-receive hook?

A:

How about adding
    . ~git/.profile
at the top of your post-receive hook script (assuming it's sh).
It's unclear exactly what you want, though.  You either want:
1) just to push to an external spot, and don't care about commonality between repos.  In which case, why do you need an environment variable from somewhere else?  Why not put the final location inside the post-receive hook script itself?
2) You want to have some external variable that controls the root of where you're going to push a lot of different repos to, and it would be better to code that location into a single variable if you ever need to change it.  If that's the case, what you're doing above makes sense.  But you don't, necessarily, need to do it in the .profile in the first place.  Clearly git is cleaning the environment for you before running your script.  So, you should instead source an external file instead that contains your parameters (though I'd argue against using .profile for this).

