On the server I have bare repository which is origin for development process and to simplify deployment to QA environment.
So in post-receive
it simply does
This git show or similar git cat-file blob approaches work more-or-less fine for text files, but they are hopeless for binary files.
Better approach which works reliably for any kind of files and even allows to checkout entire folders:
git archive mybranch folder/file.txt --output result.tar
It creates a tar archive with desired content, exactly the file that sits in the source control. Works perfectly fine with binary files.
The only thing you need to do is to extract this tar file
tar -xf result.tar
See my blogpost for more details