一、SSH提交方式
- 进入C盘用户目录,删除.ssh目录
- 运行命令生成.ssh 密钥目录:ssh-keygen -t rsa -C 邮箱
- 进入.ssh 目录查看文件列表,查看id_rsa.pub文件内容
- 登录GitHub,点击用户头像→Settings→SSH and GPG
keys - New SSH Key
- 输入复制的密钥信息
- 回到Git bash 创建远程地址别名
git remote add origin_ssh git@github.com:atguigu2018ybuq/huashan.git - 通过配置了ssh,在进行push或者pull操作时,就不需要再次输入密码。
二、Http提交方式
- 在进行http提交时,要输入用户名和密码,Windows版本的Git会默认使用Windows凭据来保存Git验证身份
- 也可以通过使用credential helper它帮我们存储了credential(凭证,里面包含了用户名和密码)
- Git会优先采用第一种方式
- Git包含了如下的两个helper
- Cache: cache 将凭据在内存中进行短时间的缓存.
git config credential.helper cache // 当前项目,暂时存储密码,默认15分钟 git config credential.helper 'cache --timeout=3600' // 当前项目,暂时存储密码,自定义时间(秒) git config credential.helper store // 当前项目,永久存储密码 git config user.name XXXX // 当前项目,设置用户名 git config user.email ***@***.com // 当前项目,设置用户邮箱
- Store: store 将凭据保存在磁盘上
git config --global credential.helper cache // 当前用户所有项目,暂时存储密码,默认15分钟 git config --global credential.helper 'cache --timeout=3600' // 当前用户所有项目,暂时存储密码,自定义时间(秒) git config --global credential.helper store // 当前用户所有项目,永久存储密码 git config --global user.name XXXX // 当前用户所有项目,设置用户名 git config --global user.email ***@***.com // 当前用户所有项目,设置用户邮箱
- Cache: cache 将凭据在内存中进行短时间的缓存.
- Windows用户可以在 C:\Users\用户名.gitconfig 文件和.git-credentials中