It turns out this was an environment variables issue. The relevant environment variable for ssh access to the remote git repo is SSH_AUTH_SOCK
.
Adding the -E
flag to the sudo command specifies that environment variables should be preserved, so this works:
sudo -E su quantka -c "git fetch"