Use a git repository on /var/www/html/
Permissions for /var/www/html folder needs to be changed.
Kindly run this command sudo chmod o+w /var/www/html
to give write access to everyone.
Once run, you should be able to transfer files in /var/www/html folder.
The problem isn't strictly with /var/www/html, it's with sudo. If you use sudo to do git, you are running it as a different user, which doesn't have access to your private ssh credentials (nor should it have).
In the other thread you pointed to there's an explanation of per user www directories, which should be one way of solving your problem. If it doesn't, you could amend the question with reasoning why it doesn't.
Update: based on the discussion, you want all content within /var/www/html owned by the user operating git repository. That you should be able to do in the way proposed by @rogerovo in a comment to this answer:
sudo chown -R _currentuser_:www-data /var/www/html && chmod -R g+sw /var/www/html