大家好,我是前端小贺,希望能够通过自己的学习输出给你带来帮助。
背景
最近公司代码准备从私有gitlab迁移到阿里的云效。就整理下如何去修改本地的git配置去链接到新的远程仓库。
正解
以下均以repo:gittest为例演示:
方法一 通过命令行直接修改远程仓库地址
- 进入gittest仓库的根目录
- 可以通过
git remote -v
查看下现在的远程仓库地址
➜ gittest git:(test) git remote -v
origin https://oldgit.com/gittest.git (fetch)
origin https://oldgit.com/gittest.git (push)
git remote set-url origin https://newgit.com/gittest.git
- 通过
git remote -v
验证下现在的远程仓库地址
➜ gittest git:(test) git remote -v
origin https://newgit.com/gittest.git (fetch)
origin https://newgit.com/gittest.git (push)
方法二 直接修改当前目录下的git配置文件
-
vim gittest/.git/config
修改
[remote "origin"]
下面的url即可[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ignorecase = true precomposeunicode = true [remote "origin"] # 原来的 url = https://oldgit.com/gittest.git url = https://newgit.com/gittest.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master [branch "dev"] remote = origin merge = refs/heads/dev
方法三 通过命令行先删除再添加远程仓库
-
进入gittest仓库的根目录
-
可以通过
git remote -v
查看下现在的远程仓库地址➜ gittest git:(test) git remote -v origin https://oldgit.com/gittest.git (fetch) origin https://oldgit.com/gittest.git (push)
-
➜ git remote rm origin ➜ git remote add origin https://newgit.com/gittest.git
-
通过
git remote -v
验证下现在的远程仓库地址➜ gittest git:(test) git remote -v origin https://newgit.com/gittest.git (fetch) origin https://newgit.com/gittest.git (push)
参考
最后
您的每一个点赞及评论都是对我坚持写作最大的支持! 另外希望各位朋友和我交流讨论,如有不对的地方,更希望批评指正!
我是前端小贺,希望能够通过自己的学习输出给你带来帮助。