2

Before this gets marked as a duplicate, I want to clarify that after Googling and trying things for a day I'm still where I started so this question is about how to debug why I'm not getting the results expected from other similar questions.

My repo has a 'develop' branch and I'm attempting to set a staging server that I can push this branch to for testing. The live server is already set up with a bare repo and post-receive hook to checkout the master branch to the web root. It works great so I started by setting up the staging server the same way. My problem is that the web root in on staging server always gets the master branch.

Based on what I've read this is the solution that should work for me: The post-receive is

#! /bin/sh
GIT_WORK_TREE=/path/to/web/root git checkout -f

The config for my local repo has this for the remote

[remote "staging"]
    url = path/to.git
    push = +develop:master

The idea being, when I run git push staging my local develop branch is pushed to the remotes master branch and that master branch is checked out to the web root.


Other things I have tried:

When applicable, I have tried with and without leading +s and -f flags.

In case the remote repo was the issue, I deleted the remote repo and web root and ran git init --bare to start from scratch

Without the push line in my local config, I changed the hook to checkout the develop branch

#! /bin/sh
GIT_WORK_TREE=/path/to/web/root git checkout -f develop

As well as running git push staging develop locally

I SSHed into the remote and ran GIT_WORK_TREE=/path/to/web/root git checkout -f develop from the bare repo. This resulted in Switched to branch 'develop', however the files in the web root still reflect the master.

At this point, I've either missed some small detail or I'm going crazy. I'm sure many people have workflows setup this way, can you tell me what I missed?


Update

per @VonCs comment, I added the branch name back to the hook and set the remote local config to push = +refs/heads/develop:refs/heads/develop. Now when I push, my local develop branch is going the the remotes develop branch and after checking the hashes with git log, I know the push is working. However, if I then run git status the return is:

# On branch develop
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   a/file/I/modified/locally

So the hook isn't executing correctly. If I run the contents of the hooks/post-receive file via SSH, it checks out correctly and my staging site is good to go. So now how do I determine why the hook wont execute and if it's related to the same issue?

To clarify, my hook currently looks like:

#! /bin/sh
GIT_WORK_TREE=/path/to/web/root git checkout -f develop
Matt R. Wilson
  • 7,268
  • 5
  • 32
  • 48
  • I like the second part better. Can you try a `git push -u staging develop`. Or change your push line into `push = +refs/heads/develop:refs/heads/develop`. Or `git push staging +HEAD:develop`, as bit as in http://stackoverflow.com/a/2980050/6309? – VonC Mar 20 '13 at 18:13
  • Can you clarify which part you mean by 'second part'? Setting the hook to checkout the develop branch? – Matt R. Wilson Mar 20 '13 at 18:32
  • The part starting with "Other things I have tried:"; where you don't try to push develop to master, but develop to staging/develop. – VonC Mar 20 '13 at 18:42
  • While the comments to this question did help me, the main reason I was having the problem is because another admin had made changes to the environment I was not aware of. So I have voted to close this question. – Matt R. Wilson Mar 22 '13 at 19:06

0 Answers0