On macOS, you can use the system keychain for security. I believe this is the most secure method for websites like Overleaf, which only offers HTTPS access (unless you link a GitHub repository of yours).
The following Git command activates this functionality.
git config --global credential.helper osxkeychain
(Additionally, as I write below, make sure you disable other credential helpers so that Git won't save your password, e.g., in plain text.)
Then, you clone the Git repository:
git clone https://git.overleaf.com/blahblah
This asks the password. Enter it, and you can see it in macOS' built-in KeyChain Access application.
In this case, you can find the entry for the URL with the name git.overleaf.com
, which matches the Git URL.
For better security, you can require all applications to ask for your permission. You can remove Git from the "Always allow access by these applications", so that even Git will not be able to get the password without your permission.
Note:
However, I noticed that some applications can still somehow Git pull without my permission. This is weird because, in this case, Overleaf's Git repository only offers https access. (I.e., there aren't any loophole through SSH.) If I change my password, I can temporarily block these applications from doing pull, but after I reregister my new password, these applications can do the pull again... Even if I check "Ask for Keychain password". Might be a misconfiguration or even a bug in macOS v13 (Ventura).
I found the problem. Git still had the configuration to store
the credential written down in the global settings (~/.git-config
). So you need to make sure you have the settings correct for different resolutions. This includes per-project, global (git config edit --system
) and system (git config edit --system
) should have the [credential]
set to helper = osxkeychain
only.
After you edit the settings, check ~/.git-credentials
and see there isn't any password stored unintentionally (in plain text).