第一步:添加目标地址、用户名、密码、到系统默认文件路径(默认是 ~ /.git-credentials
)
/.git-credentials
cat ~/.gitconfig
cd rootgitee.com
ls -a #查看所有文件:隐藏文件、可见文件
vim .git-credentials
- # 如果是gitee.com就https://user:[email protected];
- # 如果是github.com就https://user:[email protected];
- 其中user是你登陆gitee.com或者github.com的用户名,如果用户名是邮箱登陆有@,请转为%40,password是你的登陆密码,例如我的
https://zhiboqingy%40sina.com:[email protected]
查看 cat .git-credentials
显示 https://zhiboqingy%40sina.com:[email protected]
第二步:存储默认 git-credentials
配置文件
git-credentials
git config --global credential.helper store # “store” 模式可以接受一个
--file <path>
参数,可以自定义存放密码的文件路径(默认是 ~
/.git-credentials
)
cat ~/.gitconfig
显示
[credential]
helper = store
官方链接 https://git-scm.com/book/zh/v2/Git-%E5%B7%A5%E5%85%B7-%E5%87%AD%E8%AF%81%E5%AD%98%E5%82%A8#_credential_caching
第三步:免密生效检查
git clone https://gitee.com/zhiboqingy/code.git
cd code
git branch -a
git checkout develop
git fetch
git pull
以上操作,均未添加用户名和密码