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

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

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

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


当前回答

这个答案属于一个问题,我无法在其他地方找到答案:做这个项目在Gitlab,有一个子组。

git remote add origin git@gitlab.com:group/subgroup/project.git

与所有有“用户名”而不是“组”的答案相反,没有一个通过SSH为我工作。

git remote add origin https://username@gitlab.com/group/subgroup/project.git

请注意两者之间的区别是 ".com:group" 和 ".com/group" 。

如果这不是直接从盒子上工作,我使用了HTTPS方法之前成功使用SSH一个,可能是一个因素,但我不能生气尝试并重复它没有它。

其他回答

此分類上一篇

麻烦解决:

您可能遇到这些错误,当尝试更改一个远程。

这个错误意味着你试图改变的远程不存在:

git remote set-url sofake https://github.com/octocat/Spoon-Knife fatal: 没有这样的遥远的“sofake”

确保您正确输入了远程名称。

参考 : https://help.github.com/文章/变更-a-remote-s-url/

导航到本地存储库的项目根,并检查现有远程:

git remote -v

如果您的存储库使用SSH,您会看到这样的东西:

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

如果您的存储库使用 HTTPS,您会看到这样的东西:

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

取决于 git 远程 -v 的输出,您可以以以下方式更改 URL:

在 SSH 的情况下,您可以从 REPOSITORY.git 更改 URL 到 NEW_REPOSITORY.git 如下:

$ git remote set-url origin git@github.com:USERNAME/NEW_REPOSITORY.git

而在 HTTPS 的情况下,您可以从 REPOSITORY.git 更改 URL 到 NEW_REPOSITORY.git 如下:

$ git remote set-url origin https://github.com/USERNAME/NEW_REPOSITORY.git

注意: 如果您已更改了 GitHub 用户名,您可以按照上述相同的过程更新与您的存储库相关的用户名的更改。

git remote set-url origin git://new.location

(替代,打开.git/config,搜索 [远程“起源”),并编辑 url = 行。

你可以检查它工作,通过检查远程:

git remote -v
# origin  git://new.location (fetch)
# origin  git://new.location (push)

接下来的按钮,你将不得不指定新的上流分支,例如:

git push -u origin master

此分類上一篇: GitHub: 更改遠程 URL

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

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