I’m trying to set up a workflow where my code base is version-controlled under Git, and then deployed to a live server over SSH.

I wrote a simple shell script that I run from my machine that opens an SSH connection and then executes git pull on the remote server. However, because this is being ran under root (don’t ask) all files and folders that are then created/updated by Git are given the user/group of root too, instead of apache.

How do re-assign apache as the user/group of these files/folders? Do I need to alter my workflow, or could I just run chown and chgrp after I’ve pulled from Git? Ideally, I’d like to just fix where I’d rather treat the problem though rather than treating the symptoms.