且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Git中保存用户名和密码?

更新时间:2023-01-02 10:28:32

注意:此方法将凭据保存在PC磁盘上的纯文本中.您计算机上的每个人都可以访问它,例如恶意的NPM模块.

Attention: This method saves the credentials in plaintext on your PC's disk. Everyone on your computer can access it, e.g. malicious NPM modules.

运行

git config --global credential.helper store

然后

git pull

提供用户名和密码,以后将记住这些详细信息.凭证存储在磁盘上的文件中,磁盘权限为仅用户可读/可写".但仍然是纯文本.

provide a username and password and those details will then be remembered later. The credentials are stored in a file on the disk, with the disk permissions of "just user readable/writable" but still in plaintext.

如果您以后想要更改密码

If you want to change the password later

git pull

将失败,因为密码不正确,然后git从~/.git-credentials文件中删除有问题的用户+密码,因此现在重新运行

Will fail, because the password is incorrect, git then removes the offending user+password from the ~/.git-credentials file, so now re-run

git pull

提供一个新密码,使其可以更早地工作.

to provide a new password so it works as earlier.