设置记住密码:
# 默认缓存(默认15分钟)
git config --global credential.helper cache
# 指定缓存时长
git config credential.helper 'cache --timeout=3600'
# 长期存储密码
git config --global credential.helper store
增加远程地址的时候带上密码也是可以的(不建议)
# 进入仓库所在目录
cd projectfolder/
# 移除远程ssh方式的仓库地址
git remote rm origin
# 增加https远程仓库地址
git remote add origin http://yourname:password@git.oschina.net/name/project.git
http(s)->ssh
# 生成密钥对
ssh-keygen -t RSA -C email@email.com
# 添加 id_rea.pub 到仓库
# 如果本地仓库是使用的 http(s) 的需要执行如下操作,如果本身就是 ssh 克隆的,请忽略
git remote rm origin
git remote add origin git@gitee.com:{your path}/{project name}.git
重置凭证
当密码修改或重置后,也需要同步修改 credential
中的密码,可以使用如下命令,重置 credential 存储的密码
# 重置所有密码。也可以通过参数重置指定范围内的密码。具体请参照 git credential --help
git credential reject
# 或者
git config --global --unset credential.helper
git config --system --unset credential.helper