We are currently a team of 3 developers working in a project using gitlab.com
We have two servers, one for production and one for testing, both running on different droplets.
After we're done with our changes, we push to the testing server where we have this Git post-receive hook (it's a bare repository):
#!/bin/sh
git --work-tree=/var/www/domain.com --git-dir=/var/repo/site.git checkout -f
We use a branch named 'testing' (which is checked out in the testing server), so everything works fine. After everything is OK, we merge that into master and then push to production. The issue here is that there might be sometimes where we need to create a branch to fix a bug in production but we don't want to upload the work in progress in our testing branch, and we also want to test out this hotfix branch in our testing server.
That's why I figured we could just checkout the incoming branch in the testing server, so everyone can test their code on a live server without always having to have the testing branch checked out. Can this be done? I tried googling the git environment var for the incoming branch which would make it trivial from there but didn't get any luck. I know we all could just push and the manually checkout the branch in the testing server but that solution is not appealing. It would be more efficient to do just with git push and let the server handle the rest!
This is definitely not the best way for deployment using Git, so I'm all ears for suggestions!
First, there is no way to get the incoming branch from a push, because there is no such a thing as a specific incoming branch associated with a push.
Any
push
consists of a number ofcommits
. Thecommits
can be on a single branch, but they can also be on multiple branches. You can even push commits that are not on any named branch.So the question does not really make sense in this regard.
Second, why do you want your production server to not see the non-
master
branches? If the production server has themaster
branch checked out, then thehotfix
branch won't be deployed automatically, just because it it is recorded in the.git/
directory. So there is actually little harm that can be done with pushing an unused branch.Third, if you are absolutely sure that you must not push any unused branches to the deployment system (e.g. because the deployment server belongs to a customer who must not see the hotfix before they've payed for it), you can of course push specific branches with