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

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

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

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


当前回答

移除远程

使用 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 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

更改远程上流: git 远程设置 URL 起源 <url>


要添加更多升级: git remote 添加新位置 <url>

因此,您可以选择在哪里工作 git push 起源 <branch> 或 git push newplace <branch>

移除远程

使用 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)

进入文件夹/repo,您要更改并执行下面的命令:

下面的命令将改变 repo 的 git fetch URL。

git remote set-url origin <your new url>.git

下面的命令将改变 repo 的 git push URL。

git remote set-url --push origin <your new url>.git

下面的命令检查上面的变化是否反映

git remote -v

如果您正在使用 TortoiseGit 然后遵循下面的步骤:

转到您的本地查询文件夹,然后右键单击转到 TortoiseGit -> 设置 在左键中选择 Git -> Remote 在右键中选择起源 现在更改 URL 文本框值到您的新远程存储库的位置

你的分支和所有的地方承诺将保持不稳定,你可以继续像以前那样工作。