1、使用ssh
请参考:如何生成SSH key
2、使用https
1、一定要配置过.gitconfig文件
没配置过的看这里1.6 起步 - 初次运行 Git 前的配置
2、在路径C:\Users\电脑用户名,创建 .git-credentials文件
命令行创建文件:文件夹右击-右键菜单-git Bash Here
touch .git-credentials
手动创建文件:新建文本名为:. ,打开另存为,文件名删掉.txt,保存类型选择:All types(*.*),保存。
3、cmd输入一下命令
git config --global store
打开C:\Users\电脑用户名\.gitconfig,可以发现多了credential节点,节点内容如下。
[credential]
helper = store
将节点改为
[credential]
helper = store --file $HOME/git-credentials/
helper = store
4、下次再次拉git代码,弹窗输出账号密码。账号密码会以明文的方式存储在C:\Users\电脑用户名\.git-credentials文件里。
3、使用Git Credential Manager for Windows
运维好像比较倾向于用这个,因为不知道怎样改密码,据说这个可以清除掉缓存在git中的用户名和密码(看着uninstall怎么感觉好像卸载啊....这个真的不熟悉),后来我就换成上述使用https明文方式保存账号密码了。
uninstall
介紹好用工具:Git Credential Manager for Windows (記憶 Git 常用密碼)
Git-Credential-Manager-for-Windows github地址
[Git]重设和永久保存用户名密码
其他命令:
1、查询自己系统支持的crendential(凭证)
git help -a | grep credential
2、查看自己电脑的 git 的全局配置
git config --list
参考:
git保存用户名密码的方式
Git凭证存储(简单易懂,一学就会,认真看)
7.14 Git 工具 - 凭证存储
git-credential-store - Helper to store credentials on disk
git 缓存密码导致的不能和远程仓库交互unable to access... 403错误