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
相关推荐
irisMoon0639 分钟前
GitHub Copilot
github·copilot
Asurplus4 小时前
Centos7安装Git环境
git·centos·yum·dnf
m0_743125135 小时前
claude --version 报错Claude Code on Windows requires git-bash (https://git-scm.com/downloads/win).
开发语言·git·bash
AntoineGriezmann6 小时前
Git:新建功能分支并解决 Merge 冲突
git
消防大队VUE支队6 小时前
家里到底连了多少设备?这款开源神器让你一目了然
github
逛逛GitHub7 小时前
9 个 超绝的 AI 控制电脑 GitHub 开源项目。
github
Sylus_sui7 小时前
Git快速创建并推送新分支
git
悠悠子衿121388 小时前
Claude+VSCODE配置git导致频繁弹出git bash 的CMO窗口解决方法
ide·git·vscode
QC七哥10 小时前
伪造git提交记录生成点阵字符
git·github
HilariousDog10 小时前
git仓库中克隆文件同时保存line history / 行提交历史的方法介绍
git