我在一个USB钥匙上有一个 repo(origin),我在我的硬盘(本地)上克隆了它。我把"origin"搬到了NAS上,并成功测试了从这里克隆它。
我想知道我是否可以在"local"的设置中改变"origin"的URI,这样它现在就可以从NAS中提取,而不是从USB钥匙中。
现在,我可以看到两个解决方案。
把所有东西推送到usb-orign上,然后再复制到NAS上(由于nas-origin的新提交,这意味着大量的工作)。
在"local"添加一个新的远程,并删除旧的(我担心我会破坏我的历史)。
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)
来自: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
详见man page。
如果你用的是旧版本,那就试试这个。
需要注意的是,这只适用于同一个服务器,只是名称不同。
假设新的主机名是 "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
另见 GitHub: 更改远程'的URL][0]
[0]: https://help.github.com/articles/changing-a-remote-s-url/
打开终端。
第一步:-将当前工作目录改为本地项目。
第二步:-列出你现有的远程目录,以获得你想改变的远程目录的名称。
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。
第三步:- git remote set-url origin [email protected]:USERNAME/REPOSITORY.git
。
第四步:-现在验证远程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
为你...
如果你使用的是TortoiseGit,那么请按照以下步骤操作。
在左侧窗格中选择`Git -> 远程"。
在右侧窗格中选择 "原产地"。
现在将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
[![步骤1--打开设置][1]][1]
[![步骤2--改变网址][2]][2]
然后编辑URL即可。
SourceTree
单击工具栏上的"设置" 工具栏上的按钮打开 "Repository Settings "窗口。
单击 "Add" 向版本库添加远程版本库路径。 将打开一个"远程详细信息" 窗口将打开。
为远程路径输入一个名称。
输入远程仓库的URL/路径。
输入远程存储库的托管服务的用户名。
点击'确定&39。 添加远程路径。
回到版本库设置窗口,单击'确定'。 新的远程路径现在应该已经添加到版本库上了。
如果你需要编辑已经添加的远程路径,只需点击'编辑&39。 按钮。 你应该被引导到"远程详情"。 窗口,在那里你可以编辑远程路径的详细信息(URL/路径/主机类型)。
要删除远程版本库路径,请单击'删除'。 按钮,即可删除远程仓库路径。
[![在此输入图像描述][4]][4]
[![在此输入图像描述][3]][3]
参考文献[支持][5]
[1]: https://i.stack.imgur.com/3Odbn.jpg [2]: https://i.stack.imgur.com/Unkr4.jpg [3]: https://i.stack.imgur.com/Mkknl.png [4]: https://i.stack.imgur.com/MnWNX.png [5]: https://confluence.atlassian.com/sourcetreekb/changing-remote-repository-path-on-sourcetree-using-git-or-mercurial-785616227.html
[![在此输入图像描述][1]][1]
[1]: https://i.stack.imgur.com/uH71e.png
故障排除:
当你试图改变一个遥控器时,你可能会遇到这些错误。 没有这样的遥控器';[名称]'。
这个错误意味着你试图更改的远程不存在。
git remote set-url sofake https://github.com/octocat/Spoon-Knife 致命的。 没有这样的远程'sofake'。
检查你是否正确输入了远程名称。
参考 : https://help.github.com/articles/changing-a-remote-s-url/
>.将远程git URI改为',而不是
'。
将远程git URI改为https://github.com
而不是[email protected]
。
git remote set-url origin [email protected]:<username>/<repo>.git
例如:
git remote set-url origin [email protected]:Chetabahana/my_repo_name.git
。
git remote set-url origin [email protected]:Chetabahana/my_repo_name.git
这样做的好处是,当你使用[ssh-agent][2]时,可以进行[git推送
自动][1] 。
#!/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
中放入一个脚本文件$HOME/.ssh/agent
,让它使用[期望][3]运行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
[1]: https://stackoverflow.com/questions/7925850/how-to-automatically-push-after-committing-in-git/57366062#57366062 [2]: https://stackoverflow.com/questions/40549332/how-to-check-if-ssh-agent-is-already-running-in-bash/57351920#57351920 [3]: https://stackoverflow.com/questions/40226053/using-cygwin-ssh-agent-is-running-but-git-is-still-prompting-for-passphrase/55779022#55779022