Currently I deploy a project to production with git, using git push production master
to a repository with the following post-receive hook:
#!/bin/bash
GIT_WORK_TREE=/home/username/www.example.com/myproject/ git checkout -f
production
is a remote, added via git remote add production ssh://server/home/username/projects/myproject.git
.
But now I need to deploy a separate branch to a separate path on the server. I did come up with a solution, but I suppose there's a better way to do it.
What I did was create a new repository on the server, myproject-alternate.git
, with a similar post-receive hook (replacing /myproject/
with /myproject-alternate/
), added this new repository with git remote add alternate ssh://server/home/username/projects/myproject-alternate.git
. Now I can deploy to the alternate path with git push alternate branchname:master
.
This works, but I have some issues:
- The command to deploy to the alternate server is not what I was expecting—more than once I forgot the
:master
at the end and the server's repository received a new branch and the post-receive hook wasn't triggered. - I'm not sure if creating a new repository on the server was the best solution, and I wonder what would happen with a larger project.
Are there other ways to accomplish this deploy flow without the mentioned issues? Maybe a better post-receive hook that uses the received branchname to deploy to the right path? (is this even possible?)