我在我的硬盘上(本地)克隆的USB键上有一个repo(起源)。我将“起源”转移到NAS,并成功测试了从这里克隆。
我想知道我是否可以在“本地”设置中更改“起源”的URI,所以它现在将从NAS中拖动,而不是从USB键。
到目前为止,我可以看到两个解决方案:
把一切推到USB起源,然后将其复制到NAS(这意味着由于NAS起源的新承诺而付出很多工作);添加一个新的远程到“本地”并删除旧的(我担心我会打破我的历史)。
我在我的硬盘上(本地)克隆的USB键上有一个repo(起源)。我将“起源”转移到NAS,并成功测试了从这里克隆。
我想知道我是否可以在“本地”设置中更改“起源”的URI,所以它现在将从NAS中拖动,而不是从USB键。
到目前为止,我可以看到两个解决方案:
把一切推到USB起源,然后将其复制到NAS(这意味着由于NAS起源的新承诺而付出很多工作);添加一个新的远程到“本地”并删除旧的(我担心我会打破我的历史)。
当前回答
对于我来说,接受的答案只在Fetch的情况下工作,但不是拖动。
git remote set-url --push origin new.git.url/here
此分類上一篇: fetch URL:
git remote set-url origin new.git.url/here
要更新 pull URL:
git remote set-url --push origin new.git.url/here
其他回答
更改远程 git URI 到 git@github.com 而不是 https://github.com
git remote set-url origin git@github.com:<username>/<repo>.git
例子:
git remote set-url origin git@github.com:Chetabahana/my_repo_name.git
优点是,当您使用 ssh 代理时,您可以自动进行 git push :
#!/bin/bash
# Check ssh connection
ssh-add -l &>/dev/null
[[ "$?" == 2 ]] && eval `ssh-agent`
ssh-add -l &>/dev/null
[[ "$?" == 1 ]] && expect $HOME/.ssh/agent
# Send git commands to push
git add . && git commit -m "your commit" && git push -u origin master
插入一个脚本文件 $HOME/.ssh/agent 让它运行 ssh-add 使用预期如下:
#!/usr/bin/expect -f
set HOME $env(HOME)
spawn ssh-add $HOME/.ssh/id_rsa
expect "Enter passphrase for $HOME/.ssh/id_rsa:"
send "<my_passphrase>\n";
expect "Identity added: $HOME/.ssh/id_rsa ($HOME/.ssh/id_rsa)"
interact
对于我来说,接受的答案只在Fetch的情况下工作,但不是拖动。
git remote set-url --push origin new.git.url/here
此分類上一篇: fetch URL:
git remote set-url origin new.git.url/here
要更新 pull URL:
git remote set-url --push origin new.git.url/here
导航到本地存储库的项目根,并检查现有远程:
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 sofake https://github.com/octocat/Spoon-Knife fatal: 没有这样的遥远的“sofake”
确保您正确输入了远程名称。
参考 : https://help.github.com/文章/变更-a-remote-s-url/
在 Git Bash 中,输入命令:
git 远程设置 URL 起源 https://NewRepoLink.git
输入信号
达尼