我在我的硬盘上(本地)克隆的USB键上有一个repo(起源)。我将“起源”转移到NAS,并成功测试了从这里克隆。

我想知道我是否可以在“本地”设置中更改“起源”的URI,所以它现在将从NAS中拖动,而不是从USB键。

到目前为止,我可以看到两个解决方案:

把一切推到USB起源,然后将其复制到NAS(这意味着由于NAS起源的新承诺而付出很多工作);添加一个新的远程到“本地”并删除旧的(我担心我会打破我的历史)。


当前回答

另一种方法是重新命名“旧”起源(在下面的例子中,我简单地称之为旧起源),并添加一个新的。

git remote rename origin old-origin
git remote add origin git@new-git-server.com>:<username>/<projectname>.git

如果你需要推你的地方状态到新的起源:

git push -u origin --all
git push -u origin --tags

其他回答

对于那些想要从 Visual Studio 2019 进行此更改的人来说

開啟 Team Explorer (Ctrl + M)

Home > 设置

Git -> 存储器设置

此分類上一篇: Edit

此分類上一篇

更改主机为 Git Origin 服务器

从: http://pseudofish.com/blog/2010/06/28/change-host-for-a-git-origin-server/

希望这不是你需要做的事情,我已经使用的服务器在一些 git 项目上合作,域名终止了,这意味着找到一个方式来迁移当地存储库以恢复同步。

更新: 感谢 @mawolf 指出,最近的 git 版本有一个简单的方式(发表于 2010 年 2 月):

git remote set-url origin ssh://newhost.com/usr/local/gitroot/myproject.git

如果你有更古老的版本,那就尝试一下:

在工作目录中编辑.git/config 文件,您应该看到如下:

[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = ssh://oldhost.com/usr/local/gitroot/myproject.git

更改 oldhost.com 到 newhost.com,保存文件,你已经完成了。

从我的有限测试(git pull 起源; git push 起源; gitx)一切似乎顺序。

移除远程

使用 git 远程 rm 命令从您的存储库中删除远程 URL。

    $ git remote -v
    # View current remotes
    > origin  https://github.com/OWNER/REPOSITORY.git (fetch)
    > origin  https://github.com/OWNER/REPOSITORY.git (push)
    > destination  https://github.com/FORKER/REPOSITORY.git (fetch)
    > destination  https://github.com/FORKER/REPOSITORY.git (push)

    $ git remote rm destination
    # Remove remote
    $ git remote -v
    # Verify it's gone
    > origin  https://github.com/OWNER/REPOSITORY.git (fetch)
    > origin  https://github.com/OWNER/REPOSITORY.git (push)

你可以

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

您也可以编辑.git/config 并在那里更改 URL。

你没有失去历史的危险,除非你做一些非常愚蠢的事情(如果你担心,只是做一个复印件,因为你的复印件是你的历史)。

转换远程URL

开放终端。

Ist 步骤: 将当前工作目录更改为本地项目。

第二步:列出您的现有远程,以获得您想要更改的远程的名称。

远程 -v

origin  https://github.com/USERNAME/REPOSITORY.git (fetch)

origin  https://github.com/USERNAME/REPOSITORY.git (push)

从 HTTPS 更改远程 URL 到 SSH 使用 git 远程设置 URL 命令。

第三步:- git 远程设置 URL 起源 git@github.com:USERNAME/REPOSITORY.git

步骤4:现在确保远程 URL 已改变。

git 远程 -v 查看新远程 URL

origin  git@github.com:USERNAME/REPOSITORY.git (fetch)
origin  git@github.com:USERNAME/REPOSITORY.git (push)