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

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

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

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


当前回答

这是非常容易和简单的;只需遵循这些指示。

要添加或更改远程起源: git 远程设置 URL 起源 githubrepurl 查看您目前在本地存储库中有哪些远程 URL: git 远程显示起源

其他回答

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

開啟 Team Explorer (Ctrl + M)

Home > 设置

Git -> 存储器设置

此分類上一篇: Edit

此分類上一篇

查看您的特权

在我的情况下,我需要检查我的用户名

我有兩個或三個存储庫,有清潔的信件。

问题是我的许可我有两个私人 git 服务器和存储库

这个第二个帐户是该新 repo 的管理员,第一个是我的默认用户帐户,我应该允许首先

移除远程

使用 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 rm origin
$ git remote add origin git@github.com:aplikacjainfo/proj1.git
$ git config master.remote origin
$ git config master.merge refs/heads/master

更改主机为 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)一切似乎顺序。