我在我的硬盘上(本地)克隆的USB键上有一个repo(起源)。我将“起源”转移到NAS,并成功测试了从这里克隆。
我想知道我是否可以在“本地”设置中更改“起源”的URI,所以它现在将从NAS中拖动,而不是从USB键。
到目前为止,我可以看到两个解决方案:
把一切推到USB起源,然后将其复制到NAS(这意味着由于NAS起源的新承诺而付出很多工作);添加一个新的远程到“本地”并删除旧的(我担心我会打破我的历史)。
我在我的硬盘上(本地)克隆的USB键上有一个repo(起源)。我将“起源”转移到NAS,并成功测试了从这里克隆。
我想知道我是否可以在“本地”设置中更改“起源”的URI,所以它现在将从NAS中拖动,而不是从USB键。
到目前为止,我可以看到两个解决方案:
把一切推到USB起源,然后将其复制到NAS(这意味着由于NAS起源的新承诺而付出很多工作);添加一个新的远程到“本地”并删除旧的(我担心我会打破我的历史)。
当前回答
查看 git 远程连接:
git remote -v
现在,将本地存储库设置为远程 git:
git remote set-url origin https://NewRepoLink.git
现在让它升级或按下使用下列代码:
git push --set-upstream 起源大师 -f
其他回答
进入文件夹/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
这是非常容易和简单的;只需遵循这些指示。
要添加或更改远程起源: git 远程设置 URL 起源 githubrepurl 查看您目前在本地存储库中有哪些远程 URL: git 远程显示起源
(仅限 Windows PS) 在所有本地休息室中重复更改服务器/协议
Get-ChildItem -Directory -Recurse -Depth [Number] -Hidden -name | %{$_.replace("\.git","")} | %{git -C $_ remote set-url origin $(git -C $_ remote get-url origin).replace("[OLD SERVER]", "[NEW SERVER]")}
git remote -v
# View existing remotes
# origin https://github.com/user/repo.git (fetch)
# origin https://github.com/user/repo.git (push)
git remote set-url origin https://github.com/user/repo2.git
# Change the 'origin' remote's URL
git remote -v
# Verify new remote URL
# origin https://github.com/user/repo2.git (fetch)
# origin https://github.com/user/repo2.git (push)
更改远程的URL
您可以通过编辑 config 文件来更改 URL。
nano .git/config
然后编辑 url 字段并设置新的 url. 保存更改. 您可以使用命令验证更改。
git remote -v