Instead of storing credentials in a plaintext file, use the macOS Keychain:
git config --global credential.helper osxkeychain
Now credentials are encrypted in your Keychain.