user1193694
user1193694

Reputation: 121

Git checkout remote bare repo to an older branch

I'm currently testing out deploying websites via Git and am having trouble understanding the following:

Currently, I have a bare remote repo on my DEV environment with a post-receive hook which sets GIT_WORK_TREE to my webroot. I push to there from my local repo with syntax like 'git push DEV master'. This works great. However, I also have a 'develop' branch which I push to DEV (the post-receive hook is set to 'git checkout -f [BRANCH_NAME]) and this also works great.

My question is for the following situation: let's say that I find a bug on DEV (pushed from 'develop' branch) but I don't have time to fix it (maybe there is a client review that day). I would love to be able to do a 'git push DEV master' (the master branch has the last bug-free push to DEV and is an ancestor of the develop commit currently on DEV) and be done with it. But, when I do this, the remote repo tells me 'Everything is up to date!' I suppose that makes sense, but what I would like to do is force git to take the push from 'master' branch and fire the post-receive hook anyway, which is necessary for proper deployment of web assets.

I tried going directly to the remote repo in ssh and attempting to checkout master from there, but it tells me I need a work tree to do this (because it's bare, I assume).

What is the correct method of doing this? I'd like to avoid doing a revert or rebase if possible, but maybe that's the only way.

Upvotes: 1

Views: 501

Answers (2)

no name
no name

Reputation: 1

Use tags. For instance tag your current deployed version as 'current', push this tag and let your post-receive-hook act on this tag.

#!/bin/sh
read oldrev newrev refname

$refname now contains /revs/tags/current and $newrev contains the hash of the tagged commit. To change to a different revision delete the 'current' tag and set it elsewhere and push the tag. This way you don't need to make dummy changes in your files.

Upvotes: 0

larsks
larsks

Reputation: 311918

, but what I would like to do is force git to take the push from 'master' branch and fire the post-receive hook anyway, which is necessary for proper deployment of web assets.

The problem is that you have already pushed the changes to your remote, so there's nothing to push. Your options include:

  • force a change in your local branch...e.g., by updating a serial number in a file, committing, and pushing.
  • just running the post-receive hook on the server by hand, filling in the necessary environment variables.

Going to the remote repository and trying to checkout the master branch should work, provided you have both a repository and a working tree (possibly by setting GIT_WORK_TREE yourself). However, this isn't going to trigger your post-receive hook, so you'll need to manually take care of any additional logic that's there.

Upvotes: 1

Related Questions