git密码提交切换SSH提交

git保存密码

每次登录都要输入密码是显示繁琐,好在git提供了保存密码的功能。
在本地工程文件夹下,.git目录,保存以下配置。

[credential]
helper = store

或者
在git bash命令行,执行命令

git config credential.helper store

如果希望全局保存,可以加--global参数

git config --global credential.helper store

git删除保存密码配置

可以直接修改配置文件,删除以下信息

[credential]
helper = store

或者
在git bash命令行,执行命令

git config --unset credential.helper manager

切换SSH提交方式

如果之前是采用帐号密码方式提交,想切换为SSH提交,可以按如下步骤操作

生成密钥对

按四次回车键。生成的gitee_id_rsa.pub是待会要用到的公钥。

ssh-keygen -t rsa -C "邮箱" -f /c/Users/用户名/.ssh/gitee_id_rsa

修改SSH配置文件

修改SSH配置文件C:\Users\用户名\.ssh\config,使之hosts文件映射关系。

# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile /c/Users/用户名/.ssh/gitee_id_rsa

# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile /c/Users/用户名/.ssh/github_id_rsa

取消保存密码配置

在本地工程文件夹下,.git目录,取消保存密码配置。

git config --unset credential.helper manager

git 切换远程仓库地址

查看远程仓库的地址

git remote -v

删除远程仓库地址

git remote rm origin

添加仓库地址,需要添加git开头的地址,不是https地址。

git remote add origin url

或者用一条命令实现,更换远程仓库地址,URL为新地址

git remote set-url origin URL

参考资料

git remote 命令
关于git 凭证存储 credential helper配置
git 更换远程地址的方法

你可能感兴趣的:(golang,java,git,ssh,elasticsearch)