github 和 gitee 配置问题及相关问题解决

一、电脑基础配置

bash 复制代码
git config --global user.name 用户名【任意名字均可,可以和账户名称一致】
git config --global user.email【账号的邮箱地址】

二、生成各自账号的 SSH 在C:\\Users\\【自己电脑的用户名】/.ssh文件夹中,ctrl右键打开 git bash 控制窗口,然后输入以下命令一直回车... 即可。

bash 复制代码
ssh-keygen -t rsa -f id_rsa.gitee -C "gitee"
ssh-keygen -t rsa -f id_rsa.github -C "github"

最终结果如下:

三、配置生成一个config文件,用记事本打开,输入以下内容

txt 复制代码
# gitHub
Host github.com
HostName ssh.github.com
User 【账号的邮箱地址】
Port 443
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa.github

# gitee
Host gitee.com
HostName gitee.com
IdentityFile ~/.ssh/id_rsa.gitee
PreferredAuthentications publickey

四、将对应的SSH配置到对应的站点

略。

五、测试连接

bash 复制代码
ssh -T git@gitee.com # 测试Gitee
ssh -T git@github.com # 测试GitHub

【或者输入yes后】提示你Hi 用户名! You've successfully authenticated, but GitHub does not provide shell access. 那么旧恭喜你万事大吉。

六、测试连接GitHub可能出现的问题:

bash 复制代码
PS C:\Users\52803> ssh -vT git@github.com
OpenSSH_for_Windows_9.5p1, LibreSSL 3.8.2
debug1: Reading configuration data C:\\Users\\52803/.ssh/config
debug1: C:\\Users\\52803/.ssh/config line 8: Applying options for github.com
debug1: Connecting to ssh.github.com [127.0.0.1] port 443.
debug1: connect to address 127.0.0.1 port 443: Connection refused
ssh: connect to host ssh.github.com port 443: Connection refused

这个问题我遇到的大部分修改端口号,我之前本来就是选择了443,然后就是代理设置也不生效,重新安装git也不生效,重新生成ssh也不管用,设置GitHub的域名地址IP也不对。。。。。 最后发现是要生成 ssh.github.com 的域名IP地址。

在文件夹C:\Windows\System32\drivers\etc下,修改 hosts 文件

配置如下:

复制代码
140.82.113.36          ssh.github.com
140.82.114.35          ssh.github.com

配置后ipconfig /flushdns刷新。然后再测试连接。

提供查询的网站

希望大家配置顺利,不会有这些奇怪的问题。参考文档

其他问题: 比如:重新生成了ssh,之前ssh依赖的工程,再push、pull会报错,我的解决方式就是:

bash 复制代码
git remote rm origin
git remote add origin 仓库名称
git push -u origin master
相关推荐
wuk9983 小时前
基于MATLAB编制的锂离子电池伪二维模型
linux·windows·github
ai小鬼头4 小时前
AIStarter如何助力用户与创作者?Stable Diffusion一键管理教程!
后端·架构·github
天天扭码5 小时前
从图片到语音:我是如何用两大模型API打造沉浸式英语学习工具的
前端·人工智能·github
&Sinnt&7 小时前
Git 版本控制完全指南:从入门到精通
git·后端
独立开阀者_FwtCoder7 小时前
【Augment】 Augment技巧之 Rewrite Prompt(重写提示) 有神奇的魔法
前端·javascript·github
极客悟道9 小时前
巧解 Docker 镜像拉取难题:无需梯子和服务器,拉取数量无限制
后端·github
Tiny2149 小时前
多人协同开发时Git使用命令
git
独立开阀者_FwtCoder10 小时前
你用 Cursor 写公司的代码安全吗?
前端·javascript·github
WebGirl10 小时前
代码Revert后再次Merge会丢失的问题
git
T__TIII11 小时前
Dify 自定义插件
人工智能·github