我在我的硬盘驱动器(本地)上克隆的USB密钥上有一个repo(origin)。我将“origin”移动到NAS并成功测试从这里克隆它。
我想知道我是否可以在“本地”设置中更改“origin”的URI,因此它现在将从NAS中提取,而不是从USB密钥中提取。
现在,我可以看到两个解决方案:
您可以
git remote set-url origin new.git.url/here
(请参阅git help remote
)或者您可以编辑.git/config
并更改其中的URL。除非你做一些非常愚蠢的事情,否则你不会有失去历史的危险(如果你担心,只要复制你的回购,因为你的回购是你的历史。)
我工作:
git remote set-url origin <project>
在Git Bash中,输入命令:
git remote set-url origin https://NewRepoLink.git
输入凭据
完成
如果您正在使用TortoiseGit,请按照以下步骤操作:
TortoiseGit -> Settings
Git -> Remote
origin
URL
文本框值更改为新远程存储库所在的位置您的分支机构和所有本地提交将保持不变,您可以像以前一样继续工作。
你有很多方法可以做到这一点:
安慰
git remote set-url origin [Here new url]
请确保您已在存储库所在的位置打开它。
配置
它放在.git / config(与存储库相同的文件夹)中
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[remote "origin"]
url = [Here new url] <------------------------------------
...
TortoiseGit
然后只需编辑URL。
SourceTree
REF。 Support
故障排除 :
尝试更改遥控器时可能会遇到这些错误。没有这样的遥远的'[名字]'
此错误表示您尝试更改的远程不存在:
git remote set-url sofake https://github.com/octocat/Spoon-Knife致命:没有这样的遥控'软化'
检查您是否正确输入了远程名称。
参考:https://help.github.com/articles/changing-a-remote-s-url/
将远程git URI更改为
[email protected]
而不是https://github.com
git remote set-url origin [email protected]:<username>/<repo>.git
好处是你可以在使用git push
时自动执行ssh-agent:
eval `ssh-agent` && expect ~/.ssh/agent && ssh-add -l
git add . && git commit -m "your commit" && git push -u origin master
当您使用expect到脚本文件时,如下所示:
#!/usr/bin/expect -f
spawn git push origin
expect "Username for 'https://github.com':"
send "<username>\n"
expect "Password for 'https://[email protected]':"
send "<password>\n"
interact
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)
Change Host for a Git Origin Server
来自: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
有关详细信息,请参见手册页。
如果您使用的是旧版本,请尝试以下操作:
作为一个警告,这只是因为它是相同的服务器,只是使用不同的名称。
假设新的主机名是newhost.com
,而旧的主机名是oldhost.com
,则更改非常简单。
编辑工作目录中的.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 origin; git push origin; gitx
)看来,一切都井然有序。是的,我知道混淆git内部结构是不好的形式。
git remote set-url origin git://new.location
(或者,打开.git/config
,寻找[remote "origin"]
,并编辑url =
线。
您可以通过检查遥控器来检查它是否有效:
git remote -v
# origin git://new.location (fetch)
# origin git://new.location (push)
下次推送时,您必须指定新的上游分支,例如:
git push -u origin master
开放式终端。
Ist步骤: - 将当前工作目录更改为本地项目。
第2步: - 列出现有的遥控器,以获取要更改的遥控器的名称。
git remote -v
origin https://github.com/USERNAME/REPOSITORY.git (fetch)
origin https://github.com/USERNAME/REPOSITORY.git (push)
使用git remote set-url命令将远程的URL从HTTPS更改为SSH。
第3步: - git remote set-url origin [email protected]:USERNAME/REPOSITORY.git
第4步: - 现在验证远程URL是否已更改。
git remote -v
验证新的远程URL
origin [email protected]:USERNAME/REPOSITORY.git (fetch)
origin [email protected]:USERNAME/REPOSITORY.git (push)
git remote set-url {name} {url}
ex)git remote set-url origin https://github.com/myName/GitTest.git
要检查git远程连接:
git remote -v
现在,将本地存储库设置为远程git:
git remote set-url origin https://NewRepoLink.git
现在使其成为上游或推送使用以下代码:
git push --set-upstream origin master -f
如果你克隆了你的本地会自动编组,
克隆它的远程URL。
你可以用git remote -v
查看它
如果你想改变它,
git remote set-url origin https://github.io/my_repo.git
这里,
起源 - 你的分支
如果你想覆盖现有的分支,你仍然可以使用它..它将覆盖你现有的...它会做,
git remote remove url
and
git remote add origin url
为了你...