IDEA 连接GitHub仓库并上传项目(同时解决SSH问题)

目录

[1 确认自己电脑上已经安装好Git](#1 确认自己电脑上已经安装好Git)

[2 添加GitHub账号](#2 添加GitHub账号)

[2.1 Setting -> 搜索GitHub-> '+' -> Log In with Token](#2.1 Setting -> 搜索GitHub-> ‘+’ -> Log In with Token)

[2.2 点击Generate 去GitHub生成Token](#2.2 点击Generate 去GitHub生成Token)

[2.3 勾选SSH后其他不变直接生成token](#2.3 勾选SSH后其他不变直接生成token)

[2.4 然后复制token添加登录账号即可](#2.4 然后复制token添加登录账号即可)

[3 点击导航栏中VCS -> Create Git Repository 创建本地Git仓库](#3 点击导航栏中VCS -> Create Git Repository 创建本地Git仓库)

[4 导航中的VCS会变为Git,上传项目到GitHub仓库](#4 导航中的VCS会变为Git,上传项目到GitHub仓库)

[4.1 确认信息](#4.1 确认信息)

[4.2 上传成功](#4.2 上传成功)

[4.3 查看GitHub仓库,上传成功](#4.3 查看GitHub仓库,上传成功)

[5 解决SSH问题错误](#5 解决SSH问题错误)

[5.1 错误](#5.1 错误)

[5.2 原因: GitHub未识别到SSH Key](#5.2 原因: GitHub未识别到SSH Key)

[5.3 解决方案: 在GitHub网站中添加SSH Key 即可](#5.3 解决方案: 在GitHub网站中添加SSH Key 即可)

[5.3.1 检查是否已有SSH密钥](#5.3.1 检查是否已有SSH密钥)

[5.3.2 如果没有SSH密钥,生成一个新的](#5.3.2 如果没有SSH密钥,生成一个新的)

[5.3.3 添加SSH密钥到ssh-agent](#5.3.3 添加SSH密钥到ssh-agent)

[5.3.4 将SSH公钥添加到GitHub](#5.3.4 将SSH公钥添加到GitHub)

[5.3.5 测试连接](#5.3.5 测试连接)



1 确认自己电脑上已经安装好Git

打开IDEA -> Setting -> 搜索Git -> Test

2 添加GitHub账号

2.1 Setting -> 搜索GitHub-> '+' -> Log In with Token

2.2 点击Generate 去GitHub生成Token

2.3 勾选SSH后其他不变直接生成token

2.4 然后复制token添加登录账号即可

3 点击导航栏中VCS -> Create Git Repository 创建本地Git仓库

4 导航中的VCS会变为Git,上传项目到GitHub仓库

点击Git -> GitHub -> Share Project on GitHub

4.1 确认信息

4.2 上传成功

若失败看最后的错误 [5 解决SSH问题错误](#5 解决SSH问题错误)

4.3 查看GitHub仓库,上传成功

5 解决SSH问题错误

5.1 错误

Successfully created project 'AlgorithmTraining' on GitHub, but initial push failed: Warning: Permanently added 'github.com' (ED25519) to the list of known hosts. git@github.com: Permission denied (publickey). Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

5.2 原因: GitHub未识别到SSH Key

5.3 解决方案: 在GitHub网站中添加SSH Key 即可

5.3.1 检查是否已有SSH密钥

首先,检查你是否已经有一个SSH密钥:

bash 复制代码
ls -al ~/.ssh

5.3.2 如果没有SSH密钥,生成一个新的

如果你没有看到任何密钥文件,你需要生成一个新的SSH密钥:

bash 复制代码
ssh-keygen -t ed25519 -C "你的邮件地址"

如果你使用的是较老的系统,不支持ed25519,你可以使用rsa:

bash 复制代码
ssh-keygen -t rsa -b 4096 -C "你的邮件地址"

然后一直按Enter,使用默认设置。

5.3.3 添加SSH密钥到ssh-agent

确保ssh-agent正在运行,然后将你的SSH密钥添加到ssh-agent:

5.3.4 将SSH公钥添加到GitHub

复制你的公钥到剪贴板:

bash 复制代码
cat ~/.ssh/id_ed25519.pub  # 如果你使用的是rsa密钥,请将id_ed25519.pub改为id_rsa.pub

然后登录GitHub,进入 SSH和GPG密钥设置页面https://github.com/settings/keys点击 "New SSH key",粘贴你的公钥,并保存。

5.3.5 测试连接

测试是否能够成功连接到GitHub:

bash 复制代码
ssh -T git@github.com

这表示你已经成功连接到GitHub。

bash 复制代码
Hi username! You've successfully authenticated, but GitHub does not provide shell access.

之后重来之前的[4 导航中的VCS会变为Git,上传项目到GitHub仓库](#4 导航中的VCS会变为Git,上传项目到GitHub仓库)步骤即可。

相关推荐
小龙1 小时前
【Git 报错解决】本地无有效提交无法推送(`src refspec main does not match any`)
git·github·报错
小扶苏1 小时前
删除git全局账号信息并设置成新的账号密码命令
git
Greg_Zhong4 小时前
Git创建任务分支进行开发,最后合并主分支master【纯git命令执行过程】阐述
git
眯眼因为很困啦5 小时前
GitHub Fork 协作完整流程
前端·git·前端工程化
行百里er6 小时前
一个还没写代码的开源项目,我先来“画个饼”:Spring Insight
后端·开源·github
知行力6 小时前
【GitHub每日速递 20260108】告别云服务弊端,Memos隐私至上自托管笔记服务来袭!
笔记·github
AlexDeng7 小时前
Git 中模糊搜索分支名称并创建本地跟踪分支
git
无限进步_7 小时前
【数据结构&C语言】对称二叉树的递归之美:镜像世界的探索
c语言·开发语言·数据结构·c++·算法·github·visual studio
CoderJia程序员甲8 小时前
GitHub 热榜项目 - 日榜(2026-1-7)
人工智能·ai·大模型·github·ai教程
逛逛GitHub8 小时前
GitHub 上 2300 点赞的搜索 Agent,有点惊艳啊。
github