After hours of playing around with ssh, sudo, user permissions etc. trying to deploy a PHP website from a Github repository, the best solution I could find was to not use Github at all. I am a big fan of Git and Github, but automatically deploying a website from a Github repository was very fiddly and in the end more trouble than it was worth.
Compare versions of a file in git
Super quick tip because I'm always forgetting - if you want to compare an older version of a file with the most recent version in your git repository: