简介
xxxxxx
参考链接
使用
1. 清除全局用户配置
清除之前可以通过下面指令查看是否有配置全局用户,如果发现列出的列表存在user.name 和 user.email,则清除
git config --global --list
git config --global --unset user.name
git config --global --unset user.email
2. 生成ssh密钥
密钥在windows中存放在C:/Users/你的用户/.ssh/中,可以先清理下目录中存在的密钥消息。id_rsa和id_rsa.pub之类
ssh-keygen -t rsa -C “Your mail”
回车之后会出现以下提示,
Generatingpublic/privatersa key pair.Enter fileinwhich to save the key (C:/Users/admin/.ssh/id_rsa):
默认为id_rsa,因为需要配置多账号,需要取名进行区分。 以下为两个的名称
github: id_github 工蜂: id_gitcode
之后访问.ssh文件夹应该能访问到id_github,id_github.pub 和 id_gitcode,id_gitcode.pub 文件
3. 将生成的密钥添加到git的ssh中
这里只列举步骤(以github为例子),不做具体。具体网站得自行查找配置
- 登录github网站
- settings -> SSH and GPG keys -> New SSH key
- 在.ssh文件夹复制刚才生成的pub文件内容,比如id_github.pub
- 黏贴到key中,填写Title,并Add SSH key
4. 添加密钥到ssh
ssh-add ~/.ssh/id_rsa_github // 将 GitHub 私钥添加到本地
ssh-add ~/.ssh/id_rsa_gitlab // 将 GitLab 私钥添加到本地
添加完毕后,可以通过执行 ssh-add -l 验证下是否添加成功,下面实例打码过的,请勿纠结
3027 SHA256:----------key----------- email (RSA)
3027 SHA256:----------key----------- email (RSA)
添加的时候可能会出现Error connecting to agent: No such file or directory 错误
可能是ssh-agent服务没有开启,使用管理员命令行窗口执行以下命令
Set-Service -Name ssh-agent -StartupType Manual
Start-Service ssh-agent
如果还是不行检查路径问题
5. 管理密钥
在.ssh文件夹中查找config文件,如果没有则创建。添加如下内容。User 为自己的用户名
Host github
HostName github.com
User name
IdentityFile ~/.ssh/id_github
Host gitcode
HostName git.code.tencent.com
User name
IdentityFile ~/.ssh/id_gitcode
使用ssh -T命令查看是否可以连通
ssh -T git@github
Hi name! You've successfully authenticated, but GitHub does not provide shell access.
6. 使用多账号
git 的配置分为三级别,System —> Global —>Local。System 即系统级别,Global 为配置的全局,Local 为仓库级别,优先级是 Local > Global > System。 即提交仓库会先查看Local,如果没有则查找Local,如果没有则使用System。接下来我们只需要为每个仓库单独配置用户名信息即可。比如: \
git config --local user.name "name"
git config --local user.email "name@email.com"
执行完毕后,通过以下命令查看本仓库的所有配置信息:
git config --local --list