0

I am trying to create a post update script and use git as a deployment tool on a remote server.

My post-update script looks something like this

git update-server-info

for ref in $@;do
                echo $ref
                if [ "$ref"  = "refs/heads/production" ]
                then
                        ssh [email protected] GIT_WORK_TREE=/home/www/test git checkout -f production
                fi
done

However, when I run that, an error comes back that says:

Not a git repository (or any of the parent directories): .git

Which doesn't make any sense because I am able to run git commands from within the directory over ssh. enter image description here

Is there something else that I need to be doing in my post-update script?


Solution

I added the GIT_DIR variable, so now my command looks like:

ssh [email protected] GIT_DIR=/home/www/test/.git GIT_WORK_TREE=/home/www/test git checkout -f production

1 Answer 1

3

You also need to set the GIT_DIR environment variable - try the following:

ssh [email protected] GIT_WORK_TREE=/home/www/test GIT_DIR=/home/www/test/.git git checkout -f production

The rules about GIT_DIR and GIT_WORK_TREE (and their equivalents, --git-dir=<> and --work-tree=<>) are so counter-intuitive to me that I now make it a rule that if I'm setting either one of them, I should set both, and furthermore make sure that they're both set to absolute paths.

Sign up to request clarification or add additional context in comments.

1 Comment

That's it. The working directory of your SSH session will probably be the home directory of git – something like /home/git.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.