I have a big private repository which is maintained on a local network. I'd like to automatically push a subtree of that repository outside of that network. I need it to be simple:
*Task* someone pushes to local remote repository --> a subtree is automatically pushed to some other repository
I am not sure if this could be achieved with a server side hook because AFAIK there is no such thing as pushing subtrees from bare remotes. I came up with two ideas:
post-commit-hook
and make every user install it, but this is terrible, isn't it? Git book specifically states that policies should be enforced on server side.Is there a simple way of achieving something like this? Or is this impossible and it's just git abuse?
Umm, I'm a bit embarrassed. Apparently this was much easier than I thought. Here is a hasty solution which builds on @wrzasa suggestion:
Clone your repository on the server to which you are pushing, like this (dir.git is a bare repo):
.
|- dir.git
|- dir
In dir
do: git remote add <remote-name> <remote-address>
In dir.git/hooks/post-receive
put:
#! /bin/bash
unset GIT_DIR
cd ../dir
git pull ../dir.git
git subtree split --prefix=<subdir-in-dir> --branch=<branch-name>
git push <remote-name> <branch-name>
Remember to make post-receive
executable. See this answer if you wanna know why unset GIT_DIR
is needed.
That's pretty much it. Now whenever someone pushes to dir
remote (i.e. dir.git
) subtree under <subdir-in-dir>
will be pushed to <remote-name>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With