Git can be configured to remember passwords.
How one may check whatever given domain has stored password?
I found on https://git-scm.com/docs/git-credential one of available APIs.
For example, assuming that we are interested in GitHub credentials and username is stored on gitconfig we may run
git credential fill
protocol=https
host=github.com
<empty line>
that will return password if it is available in the credential cache. Unfortunately, it will lock (and ask the user for specifying password) if password is not available, what makes it unsuitable for a script.
https://git-scm.com/docs/gitcredentials seems to not have any info useful to solve this.
To avoid XY problem: I have a script that is supposed to automatically push commits from one of the repositories. It can wait with push until user authenticated and GitHub credential cache remembered a password.
I am strongly preferring cross-platform solutions (I will use it on Linux but I prefer to not rewrite my git setup on starting to use other OS).