How do I avoid the specification of the username and password at every git push?

前端 未结 18 1790
我在风中等你
我在风中等你 2020-11-28 00:02

I git push my work to a remote Git repository.

Every push will prompt me to input username and password. I would

18条回答
  •  无人及你
    2020-11-28 00:37

    Saving Indefinitely

    You can use the git-credential-store via

    git config credential.helper store
    

    which stores your password unencrypted in the file system:

    Using this helper will store your passwords unencrypted on disk, protected only by filesystem permissions. If this is not an acceptable security tradeoff, try git-credential-cache, or find a helper that integrates with secure storage provided by your operating system.

    With a Timeout

    Use the git-credential-cache which by default stores the password for 15 minutes.

    git config credential.helper cache
    

    to set a different timeout, use --timeout (here 5 minutes)

    git config credential.helper 'cache --timeout=300'
    

    Secure Saving Indefinitely (OS X and Windows)

    • If you’re using a Mac, Git comes with an “osxkeychain” mode, which caches credentials in the secure keychain that’s attached to your system account. This method stores the credentials on disk, and they never expire, but they’re encrypted with the same system that stores HTTPS certificates and Safari auto-fills. Running the following on the command line will enable this feature: git config --global credential.helper osxkeychain. You'll need to store the credentials in the Keychain using the Keychain app as well.
    • If you’re using Windows, you can install a helper called “Git Credential Manager for Windows.” This is similar to the “osxkeychain” helper described above, but uses the Windows Credential Store to control sensitive information. It can be found at https://github.com/Microsoft/Git-Credential-Manager-for-Windows. [emphases mine]

提交回复
热议问题