Git stored credentials work locally but don't have effect if logged into the machine via SSH

I have a remote macOS machine with git and GitHub Desktop installed, as well as my SSH public key.

If I connect to the machine via Screen Sharing, open a shell window and try e.g. git pull in my repository it works fine and doesn't ask for the credentials.

However, if I connect to the same machine using SSH and try the same git command, it asks for credentials every time (and works if I give it the correct username and password).

I tried a few suggestions such as this one but everything I do doesn't seem to have any effect when connecting to the machine via SSH.

Is there some sort of a policy of not updating the KeyChain via SSH? Or is it something else?

P.S. I added this to my ~.ssh/config:

Host *
  AddKeysToAgent yes
  UseKeychain yes

Doesn't seem to help.

Also, my git URL is https://github.com/...


Add ForwardAgent yes to your ~/.ssh/config under the UseKeyChain line