You have done an environment check to make sure you have what's needed for 3.9.x? PHP version ... php extensions .. DB version ... DB character set collation ... site running https?
So the moodle in /var/www/html/ is active and wasn't installed via git. The first action is to make a backup of what you have ... the moodle directory in /var/www/html/ ... a db dump ... and minimal moodledata/filedir/
Does the moodle in /var/www/html/ have addons already installed. Does it have 3rd party theme (not core) installed?
Answer those please before proceeding ... and make a list ... a plugin that is no longer compatible would/could kill all this!
What you are essentially doing then is attempting to get a moodle under git.
So above is what is called a 'side load' (dunno if that is an official term but it does describe).
*Copy* the hidden .git directory and other hidden .git files at code root of /opt/moodle/ to /var/www/html/moodle/
in /opt/moodle/ these - first is a directory ... the others are files
cp -rp .git* /var/www/html/moodle/
then cd /var/www/html/moodle/ and check git ...
git branch -a
You should see * MOODLE_39_STABLE at the top.
And to assure you are tracking the right branch ...
git branch --track MOODLE_39_STABLE origin/MOODLE_39_STABLE
git checkout MOODLE_39_STABLE
Either/both of those won't re-acquire 39 code and might show you an error that is good!
I do git reset --hard also.
At that point, ready to upgrade.
php admin/cli/maintenance.php --enable
IF all goes well
php admin/cli/maintenance.php --disable
Hit site with browser.