如何更改远程 Git 存储库的 URI (URL)? [英] How to change the URI (URL) for a remote Git repository?

查看:27
本文介绍了如何更改远程 Git 存储库的 URI (URL)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的硬盘驱动器(本地)上克隆的 USB 密钥上有一个存储库(来源).我将起源"移至 NAS 并成功测试从此处克隆它.

I have a repo (origin) on a USB key that I cloned on my hard drive (local). I moved "origin" to a NAS and successfully tested cloning it from here.

我想知道我是否可以在本地"的设置中更改来源"的 URI,这样它现在将从 NAS 中提取,而不是从 USB 密钥中提取.

I would like to know if I can change the URI of "origin" in the settings of "local" so it will now pull from the NAS, and not from the USB key.

目前,我可以看到两种解决方案:

For now, I can see two solutions:

  • 将所有内容推送到 usb-origin,然后再次将其复制到 NAS(由于对 nas-origin 的新提交意味着大量工作);

  • push everything to the usb-orign, and copy it to the NAS again (implies a lot of work due to new commits to nas-origin);

向本地"添加一个新的遥控器并删除旧的(我担心我会破坏我的历史记录).

add a new remote to "local" and delete the old one (I fear I'll break my history).

推荐答案

你可以

git remote set-url origin new.git.url/here

(请参阅 git help remote)或者您可以编辑 .git/config 并更改那里的 URL.除非您做了一些非常愚蠢的事情,否则您不会有丢失历史记录的危险(如果您担心,只需复制您的存储库,因为您的存储库就是您的历史记录.)

(see git help remote) or you can edit .git/config and change the URLs there. You're not in any danger of losing history unless you do something very silly (and if you're worried, just make a copy of your repo, since your repo is your history.)

这篇关于如何更改远程 Git 存储库的 URI (URL)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆