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.

  • Trouble cloning a git repository from an EC2 instance
  • chef deployment?
  • Access AWS CodeCommit from Jenkins running on EC2 (Ubuntu)
  • git not uploading all files
  • Unable to add ssh-key of EC2 instance to bitbucket account
  • Is there Environment variable for Amazon ElasticBeanstalk containers for the deployed version?
  • #!/bin/sh
    GIT_WORK_TREE=/var/www/mysite
    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

        #!/bin/sh
        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
    

  • Split git repository while preserving and scoping-down branches
  • zsh length of a string with possibly unicode and escape characters
  • Collaborate using Git without Remote Server
  • Managing configuration files across multiple servers
  • XCode 7: Can't Push git
  • Jenkins Build on push option is not appearing
  • Git Baby is a git and github fan, let's start git clone.