17

I've pushed a website to my remote server via Git but got the error

cannot run post-receive: No such file or directory

So the stuff is on the server, it has just not been deployed to my /public folder.

I do however have a post-receive file so I am not sure why it was not found. Now I thought all I need to do is manually run this post-receive hook to do the checkout though I don't know how...

nerdess
  • 10,051
  • 10
  • 45
  • 55
  • Check if [this](http://stackoverflow.com/questions/3563904/git-hook-post-merge-error-cannot-run) helps. – vpatil Feb 06 '12 at 11:29

1 Answers1

25

A hook is an executable shell script. You can execute it from the command line if you need to run it by hand, although constructing the expected stdin inuput is somewhat tedious if your repo has more than one head (that is, you use branches). There should be a low-level command to do this for you, but I don't know this offhand.

Assuming a bash shell and a single branch in your git repo...

# Print the log with full hashes and commit subject, so that you can
# figure out which hashes to use for the FROM and TO range.
/path/to/repo$ git log --pretty=%H\ %s

# assuming the FROM commit identifies as 999988887777
# and te TO commit identifies as 000011112222
# (Note: use the full length hashes; I've shortened them for the example)
/path/to/repo$ .git/hooks/post-receive <<MARK
999988887777 000011112222 refs/heads/master
MARK

...the above should work just like the real thing.

Barend
  • 17,296
  • 2
  • 61
  • 80
  • Ok now so I ran website.git/hooks/post-receive and got "line 1: GET_WORK_TREE: command not found" :-/ – nerdess Feb 06 '12 at 23:53
  • 4
    D'oh I found out what was wrong: it should be GIT_WORK_TREE of course not GET_WORK_TREE – nerdess Feb 07 '12 at 00:01
  • What does the MARK syntax do? I've been unable to find any docs on it. Thanks! – Xgongiveittoya Mar 02 '16 at 19:11
  • 2
    @Xgongiveittoya the MARK thing works with the `<<` operator and is called a "here document". It's not part of Git, it's part of the shell. It's a way to send a file into a pipeline without first creating a file on disk. http://ss64.com/bash/syntax-here.html – Barend Mar 03 '16 at 09:31
  • @Barend Awesome, thanks! I couldn't figure out what to google for it. – Xgongiveittoya Mar 03 '16 at 13:50
  • Running the script manually may not be the same as being run by git itsel. Firstly, the user running the script may be different. Secondly, some environment variables may change, such as GIT_DIR. – neodelphi Oct 02 '16 at 20:14
  • How I supposed to run it on Windows? – Dmitry Gusarov May 07 '17 at 13:53
  • I hardly understand git, but I had to change a couple of things from the command shown: 1. the post-receive script was not in a .git/ sub-directory. It was in `./hooks/post-receive` 2. `git log` only listed one hash, perhaps because I only have one commit? So, I just used one hash instead of two in the here document part. – Winston Smith Dec 17 '22 at 22:37
  • 1
    @WinstonSmith first part sounds like you were looking at a bare repository. Second idk, but may indeed be on account of having just one commit. – Barend Jan 11 '23 at 13:56