Post-receive hook to pull from bare repo

On our server we have, for each project, 2 folders: /repository and /htdocs. Htdocs being a clone of repository, which is the bare repo. Every developer has his own repository clone to work in. htdocs is there to preview the project to project managers.

I would like to set up a post-receive hook that automatically updates htdocs when updates are pushed from the developers.

  • Setting up Notepad++ Compare as the diff tool in git?
  • git submodule sync doesn't work
  • the correct way of git rebase
  • When to start versioning/stop using project references
  • How to get an Ansible check to run only once in a playbook?
  • Error when creating branch in git
  • I have following in my post-receive hook:

    #!/bin/sh
    GIT_WORK_TREE=../htdocs git pull origin master
    

    However, when I push, I see following error: git error

    Can anyone tell me what’s going wrong?

    Note that

    #!/bin/sh
    GIT_WORK_TREE=../htdocs git checkout -f
    

    works, but this is kinda slow (as the project is pretty big). It is also possible someone made some bugfixes in htdocs that would get lost with checkout -f if they weren’t committed.

  • Transitioning git repos to submodules inside git-annex?
  • How does one push from NTFS (desktop) to FAT32 (usb)?
  • Deployment to heroku with “private” config file
  • Linux kernel which version changed the function parameters
  • Integration between any git repository and versionone commitstream
  • Adding git diff in push notification mail
  • One Solution collect form web for “Post-receive hook to pull from bare repo”

    This should work:

     GIT_WORK_TREE=../htdocs GIT_DIR=../htdocs/.git git pull origin master
    

    If you don’t specify GIT_DIR, git believe the repo is still “repository” (the bare repo), which might not have a remote named “origin” (hence the error message).

    Git Baby is a git and github fan, let's start git clone.