一、创建单密码存储(git-credential-helper)
在工作目录下创建.git-credentials文件:
vim .git-credentials
输入:https://{username}:{password}@github.com
注:1.如果远程仓库是用http协议,则输入 http://{username}:{password}@github.com
2.如果用户名密码有特殊字符,则用双引号
创建或者添加~/.gitconfig文件:
git config --global credential.helper store
重新拉取一次代码,正确输入一次用户名/密码后,后面就可以免密了!!
二、多密码存储(git-credential-store)
git-credential-store是git提供的另一个工具,可以用来管理用户名和密码,并将它们存储在本地的文件中。相比于git-credential-helper,git-credential-store在用户交互中更加便捷。要使用git-credential-store来配置多个用户名和密码。
创建~/.git-credentials-store文件
vi ~/.git-credentials-store
protocol=https
host=github.com
username=your_username
password=your_password
protocol=https
host=your-git-url.com
username=your_username
password=your_password
#需要将上面的`your_username`和`your_password`替换为实际的用户名和密码,`github.com`和`your-git-url.com`替换为对应的远程仓库地址
重新拉取一次代码,正确输入一次用户名/密码后,后面就可以免密了!!