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
相关推荐
摇滚侠1 小时前
VScode 提交代码 Git
git
YuforiaCode4 小时前
移除原有 Git 仓库关联,在IDEA中重新初始化 Git 并推送到新仓库(详细图解、包含相关问题的解决办法)
git
UIUV4 小时前
Git程序员入门笔记:从零开始掌握分布式版本控制
git
星光不问赶路人4 小时前
彻底清理 Git 分支:从查看到批量删除无效分支的全流程指南
git·github
逛逛GitHub7 小时前
推荐 4 个实用、好玩儿的 GitHub 开源项目。
github
SelectDB8 小时前
Apache Doris 与 ClickHouse:运维与开源闭源对比
大数据·数据分析·github
如果是君9 小时前
【git使用】ubuntu下利用git工具提交一个工程
linux·git·ubuntu
CoderJia程序员甲10 小时前
GitHub 热榜项目 - 日榜(2025-10-20)
ai·开源·大模型·github·ai教程
吃鱼吃鱼吃不动了10 小时前
常用的 git 命令
git
spionbo10 小时前
Java Stream API中如何实现数据的并行处理?
github