Git Remote 仓库地址变更

Background

GitHub 上的仓库名从 old-repo 改为了 new-repo,本地 clone 的 remote URL 需要同步更新,否则 push/pull 会 404。

问题现象

bash 复制代码
$ git remote -v
origin  git@github.com:username/old-repo.git (fetch)
origin  git@github.com:username/old-repo.git (push)

仓库已重命名为 new-repo,旧 URL 不再有效。

解决方法

bash 复制代码
git remote set-url origin git@github.com:username/new-repo.git

命令解析

部分 含义
git remote set-url 修改已有 remote 的 URL,不影响 tracking 关系
origin 要修改的 remote 名称
git@github.com:username/new-repo.git 新的仓库地址(SSH 协议)

SSH vs HTTPS

协议 URL 格式 特点
SSH git@github.com:username/new-repo.git 免密推送,需配置 SSH key
HTTPS https://github.com/username/new-repo.git 每次需输入凭证(或配置 credential helper)

如果本地已配置 SSH key,推荐使用 SSH 格式保持一致。

验证

bash 复制代码
$ git remote -v
origin  git@github.com:username/new-repo.git (fetch)
origin  git@github.com:username/new-repo.git (push)

Summary

  • GitHub 仓库 rename 后,本地 remote URL 需要手动更新
  • git remote set-url 是最简洁的方式,不会破坏任何 branch tracking 配置
  • 保持协议风格一致(SSH or HTTPS),避免混用

References

相关推荐
ModestCoder_7 小时前
Git 忽略所有 `.xlsx`,但保留指定 Excel 文件的方法
git·excel
阡陌..8 小时前
202605新版git_2.54.0常用操作指令
大数据·git·elasticsearch
会笑的小熊9 小时前
VScode项目推送到git仓库
ide·git·vscode
zhangfeng11339 小时前
宝塔服务器完全可以安装 Git,进行版本管理,而且非常简单
运维·服务器·人工智能·git·编程
Bdygsl11 小时前
Git(1)—— 基本理解与使用
git
JiaWen技术圈12 小时前
增量静态再生(ISR)详解:Next.js 中的实现与应用
javascript·git·ubuntu
The Chosen One98513 小时前
【Linux】深入理解Linux进程(二):进程的状态
linux·运维·服务器·开发语言·git
TimberWill14 小时前
git worktree实现分支管理
git
普修罗双战士14 小时前
项目设计-文章系统发布文章完整前后端设计
java·数据库·vue.js·spring boot·git·intellij-idea