why doesn't my git post-receive hook seem to work

I have an Amazon EC2 instance that’s running linux and has git installed. I setup a git repo with the following command.

git init --bare

I then cd into the hooks directory and created a post-receive file that has the following bash script.

  • Keep certain existing files when deploying to Elastic Beanstalk through aws.push
  • Problems with git submodules when submodules are private Github repos
  • Dummy questions about setting up git on amazon cloud ec2
  • how to deploy my ruby on rails app with git in my ec2 instance?
  • Correct Path for Git Remote Add from Amazon EC2 Instance to OSX Client Machine
  • What is the default Jenkins password?
  • #!/bin/sh
    export GIT_WORK_TREE
    git checkout -f

    when I push from my local repo to the server everything seems to go well. I tested this by adding a new file called myfile.html to my project and pushing to the server. I don’t get any errors. However, when I cd to /var/www/mysite directory I don’t see the new file that I added, but if I clone the remote repo to a new directory locally I do get all the changes that I pushed to the server.

    My thought is that changes are being tracked by git just fine but when the post-receive runs maybe some sort of permissions issue is keeping the files from getting moved and applied to my /var/www/mysite directory ?

    Hoping someone can shed some light on what may be happening and how to trouble shoot this.


    So basically the post-receive file needed the following permissions set to make it executable.

    chmod +x post-receive 

    After doing that I now have an actual permissions issue with where I’m telling git to move the files when they are pushed and the post-receive runs.

    My guess is that the post-receive is trying to move the files to /var/www/mysite folder like I’m asking but it now gives me access denied errors when trying to move and change files.

    I tried adding sudo to my post-receive script like so

        sudo GIT_WORK_TREE=/var/www/mysite
        export GIT_WORK_TREE
        sudo git checkout -f

    doing that gave me the following error when I pushed code.

    remote: usage: sudo [-D level] -h | -K | -k | -V
    remote: usage: sudo -v [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-u user
    remote:             name|#uid]
    remote: usage: sudo -l[l] [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-U user
    remote:             name] [-u user name|#uid] [-g groupname|#gid] [command]
    remote: usage: sudo [-AbEHknPS] [-r role] [-t type] [-C fd] [-D level] [-g
    remote:             groupname|#gid] [-p prompt] [-u user name|#uid] [-g groupname|#gid]
    remote:             [VAR=value] [-i|-s] [<command>]
    remote: usage: sudo -e [-AknS] [-r role] [-t type] [-C fd] [-D level] [-g
    remote:             groupname|#gid] [-p prompt] [-u user name|#uid] file ...
    remote: fatal: This operation must be run in a work tree

  • How do pull no fast-forward in TortoiseGit
  • resolve git conflicts for particular files by automatic merge all changes
  • Git config with directory scope, containing multiple repositories
  • Unable to remove fast many files in Git
  • AWS 'eb deploy' always zip all files
  • How to get last Git tag matching regex criteria
  • Git Baby is a git and github fan, let's start git clone.