Some of the other commenters suggest adding git-dir and work-tree to the git commands, but there's a better solution: use the --separate-git-dir option when cloning the repository. For example: git clone --separate-git-dir= where is outside of any directory served by the web server and is the htdocs root. This option makes /.git a file whose content is: gitdir: The advantage is that all git commands work as usual, wi…
It may be possible that gitdir is still accessible through a misconfiguration or security issue (and you're giving them exactly where to look)
Production servers have no business having the .git directory anywhere.