github 远程仓库名或地址修改,本地如何同步

1.背景

github远程仓库名变更,导致本地仓库失效。如何在原有仓库的基础上让本地仓库和新的远程仓库建立关联。

假设:

 本地git项目目录为:testGit/    

 本地添加的远程仓库名为:origin    

 旧的远程仓库地址:https://github.com/yohayoha/testGit1.git    

 新的远程仓库地址:https://github.com/yohayoha/testGit.git

2.方法

方法一 直接修改远程地址

  1. 进入testGit/ 根目录
  2. git remote 查看所有远程仓库:git remote xxx 查看指定远程仓库地址(ps:此处的xxx为origin)
  3. 修改旧仓库地址为:git remote set-url origin https://github.com/yohayoha/testGit.git
  4. 查看地址是否已修改:git remote -v

方法二 先删除远程仓库再添加远程仓库

  1. 进入testGit/ 根目录
  2. git remote 查看所有远程仓库, git remote xxx 查看指定远程仓库地址
  3. git remote rm origin
  4. git remote add origin https://github.com/yohayoha/testGit.git

方法三 修改配置文件

  1. 进入 testGit/ 根目录
  2. vim config
  3. 修改[remote "origin"] 下面的url地址
![图片](https://www.cnblogs.com/images/cnblogs_com/Ponchien/1502018/o_%e4%bc%81%e4%b8%9a%e5%be%ae%e4%bf%a1%e6%88%aa%e5%9b%be_20190712093740.png)
posted @ 2019-07-12 09:46  等风等雨等着你  阅读(1818)  评论(0编辑  收藏  举报