GitHub的codespaces入门,以及git设置

一、vscode连接代码仓库repository

1, 安装codespaces插件

在remote explorer里面连接codespaces

二、在Windows terminal里面(或者xshell)连接此容器

1,安装GitHub CLI
bash 复制代码
PS C:\Users\yan> cd 'D:\Program Files\GitHub CLI\'
PS D:\Program Files\GitHub CLI> .\gh.exe
Work seamlessly with GitHub from the command line.
2,授权认证此gh客户端
bash 复制代码
PS D:\Program Files\GitHub CLI> .\gh.exe
PS D:\Program Files\GitHub CLI> gh auth login -s codespace
? Where do you use GitHub? GitHub.com
? What is your preferred protocol for Git operations on this host? SSH
? Upload your SSH public key to your GitHub account? C:\xxxx\id_rsa_xxx.pub


? Title for your SSH key: (GitHub CLI)                                                                                                                                                                                                          ? Title for your SSH key: GitHub CLI
? How would you like to authenticate GitHub CLI? Login with a web browser

! First copy your one-time code: Exxx6
Press Enter to open https://github.com/login/device in your browser...
✓ Authentication complete.
- gh config set -h github.com git_protocol ssh
✓ Configured git protocol
HTTP 422: Validation Failed (https://api.github.com/user/keys)
key is already in use
2.1

"Title for your SSH key",这里按回车就行,不用输入名字

虽然最后一行显示" key in use",

但此次认证是成功的。

GitHub 不允许重复添加同一把 key

这不是错误,只是"重复添加失败"。

2.2 https和ssh两者区别:

HTTPS(推荐,大多数人),登录最省事,用 GitHub CLI 会自动帮你处理 token,不用配置密钥

SSH(进阶),需要自己生成并配置 SSH key,适合长期重度使用、自动化环境

3,通过gh auth status命令查看认证信息
bash 复制代码
PS D:\Program Files\GitHub CLI> gh auth status
github.com
  ✓ Logged in to github.com account xxxxxx(keyring)
  - Active account: true
  - Git operations protocol: ssh
  - Token: gho_************************************
  - Token scopes:  'codespace',
3.1

凭证已安全存储在 Windows keyring 里

3.2
bash 复制代码
Git operations protocol: ssh

说明以后 clone / push / pull 都会走 SSH,不需要再输入用户名密码

三、Windows terminal中通过gh.exe进入codespaces容器

1、
bash 复制代码
gh codespace ssh

可以进入容器的Linux环境

四、git push不能设置remote url为ssh格式

1,

❌ 在 GitHub Codespaces 里,强行把 remote 改成 SSH 是错误的

✅ Codespaces 默认应该用 HTTPS(带 token)而不是 SSH key,不用设置,codespaces已经设置好

2,如果已经设置为ssh格式,需要改为https格式
bash 复制代码
git remote set-url origin https://github.com/xxx/yyy.git
相关推荐
凌云拓界3 分钟前
NodeVerdict:Node.js 原生诊断数据可视化工具
信息可视化·架构·typescript·开源·node.js·github·bug
为伴只为你1 小时前
将已有git工程转为使用LFS
git
数智化管理手记1 小时前
本地云数据存储算力总是不够用?云计算如何协助架构升级?
架构·云计算·github
苏灿烤鱼1 小时前
今日 GitHub 热门|Agent 云端电脑登顶,+1,891 项目却只排第三(08.06)
github·agent·资讯
七牛开发者2 小时前
“打透” Harness:用 GitHub Copilot 跑通从原型、规划到实现与评审的 AI Coding 工作流
人工智能·github·copilot
带娃的IT创业者2 小时前
Spec-Kit 与物理智能的范式跃迁:当 GitHub 成为世界模型的协作基础设施
github·世界模型·规范驱动开发·机器人开发·开源协作·物理智能
TunerT_TQ2 小时前
Valhalla 静态工程审阅 #002|字节 LatentSync 源码证据驱动评测【大厂开源基础设施特辑】
架构·github
八号当铺2 小时前
我做了一个多端基金收益助手:从养基宝数据到 Web、桌面端、浏览器插件和 IDE 插件
前端·人工智能·github
x-cmd3 小时前
AI 时代的 Git 革命:多 Agent 并发开发的新基础设施
git·ai·agent·代码管理·开发者工具·多智能体协作·worktree
一次旅行3 小时前
OpenAI 新版提示词指南
人工智能·chatgpt·github