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

相关推荐
lsc_blog19 小时前
年底还在招的岗位,先确认缺口和到岗要求
git·缓存·ci/cd·职场和发展·github
全栈陈序员1 天前
【Git】从入门到精通(十一)—— git reset 三种模式详解
git·elasticsearch
全栈陈序员1 天前
【Git】从入门到精通(十)—— 撤销与恢复:git checkout与git restore
运维·网络·数据库·git
全栈陈序员1 天前
【Git】从入门到精通(五)—— git add:将文件加入暂存区
大数据·git·elasticsearch
全栈陈序员2 天前
【Git】从入门到精通(七)—— git status:查看仓库状态
大数据·git·elasticsearch
莫晓燚2 天前
Ansible 13 个常用模块---企业实战
git·github
无言听风雨丶2 天前
Kubernetes GitOps 持续交付实战:用 Argo CD 让 Git 成为集群事实源
git·elasticsearch·kubernetes
全栈陈序员2 天前
【Git】从入门到精通(六)—— git commit:提交到版本库
大数据·git·elasticsearch
全栈陈序员3 天前
【Git】从入门到精通(一)—— Git简介:什么是版本控制系统
大数据·git·elasticsearch
大猫会长3 天前
git笔记
git