文章

🍀Git:更换远程仓库

一、查看当前远程仓库

运行以下命令查看当前的远程仓库配置:

git remote -v

输出类似:

origin  https://github.com/old-repo.git (fetch)
origin  https://github.com/old-repo.git (push)

二、更换远程仓库地址

方法一:修改远程仓库地址

使用 set-url 命令更改远程仓库地址:

git remote set-url origin 新的远程仓库地址

示例:

git remote set-url origin https://github.com/new-repo.git

方法二:删除旧的远程仓库并添加新的

  1. 删除旧的远程仓库

git remote remove origin
  1. 添加新的远程仓库

git remote add origin 新的远程仓库地址

示例:

git remote add origin https://github.com/new-repo.git

三、验证更改

再次运行以下命令,确认远程仓库地址已更换:

git remote -v

四、推送代码到新的远程仓库

根据需要将代码推送到新的远程仓库:

git push -u origin main

License:  CC BY 4.0