如何更改远程Git存储库的URI(URL)?
我在我的硬盘(本地)上克隆的USB密钥上有一个repo(源)。我将“源”移动到NAS,并成功地从这里测试了克隆 我想知道我是否可以在“本地”的设置中更改“origin”的URI,以便它现在可以从NAS而不是从USB密钥中提取 目前,我可以看到两种解决方案:如何更改远程Git存储库的URI(URL)?,git,url,git-remote,Git,Url,Git Remote,我在我的硬盘(本地)上克隆的USB密钥上有一个repo(源)。我将“源”移动到NAS,并成功地从这里测试了克隆 我想知道我是否可以在“本地”的设置中更改“origin”的URI,以便它现在可以从NAS而不是从USB密钥中提取 目前,我可以看到两种解决方案: 将所有内容推送到usb源,然后再次将其复制到NAS(由于新提交到NAS源,这意味着大量工作) 将一个新的遥控器添加到“本地”,并删除旧的遥控器(我担心我会破坏我的历史记录) 你可以 git remote set-url origin new
- 将所有内容推送到usb源,然后再次将其复制到NAS(由于新提交到NAS源,这意味着大量工作)
- 将一个新的遥控器添加到“本地”,并删除旧的遥控器(我担心我会破坏我的历史记录)
- 你可以
git remote set-url origin new.git.url/here
(请参见git help remote
),或者您可以编辑.git/config
并在那里更改URL。除非你做了一些非常愚蠢的事情,否则你不会有失去历史的危险(如果你担心,只要复制一份你的回购协议,因为你的回购协议就是你的历史。)你可以
git remote set-url origin new.git.url/here
(请参见git help remote
),或者您可以编辑.git/config
并在那里更改URL。除非你做了一些非常愚蠢的事情,否则你不会有失去历史的危险(如果你担心的话,就复制一份你的回购协议,因为你的回购协议就是你的历史。)
发件人:
希望这不是你需要做的事情。我用来与几个git项目协作的服务器的域名过期了。这意味着找到一种迁移本地存储库以恢复同步的方法
更新:感谢@mawolf指出使用最新的git版本有一个简单的方法(2010年2月后):
有关详细信息,请参见手册页
如果您使用的是旧版本,请尝试以下操作:
作为一个警告,这只适用于同一台服务器,只是名称不同
假设新主机名是newhost.com
,而旧主机名是oldhost.com
,则更改非常简单
编辑工作目录中的.git/config
文件。您应该看到如下内容:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = ssh://oldhost.com/usr/local/gitroot/myproject.git
> origin git@github.com:USERNAME/REPOSITORY.git (fetch)
> origin git@github.com:USERNAME/REPOSITORY.git (push)
> origin https://github.com/USERNAME/REPOSITORY.git (fetch)
> origin https://github.com/USERNAME/REPOSITORY.git (push)
将oldhost.com
更改为newhost.com
,保存文件,即可完成操作
从我有限的测试(git pull origin;git push origin;gitx
)来看,一切似乎都井然有序。是的,我知道弄乱git内部是不好的
发件人:
希望这不是你需要做的事情。我用来与几个git项目协作的服务器的域名过期了。这意味着找到一种迁移本地存储库以恢复同步的方法
更新:感谢@mawolf指出使用最新的git版本有一个简单的方法(2010年2月后):
有关详细信息,请参见手册页
如果您使用的是旧版本,请尝试以下操作:
作为一个警告,这只适用于同一台服务器,只是名称不同
假设新主机名是newhost.com
,而旧主机名是oldhost.com
,则更改非常简单
编辑工作目录中的.git/config
文件。您应该看到如下内容:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = ssh://oldhost.com/usr/local/gitroot/myproject.git
> origin git@github.com:USERNAME/REPOSITORY.git (fetch)
> origin git@github.com:USERNAME/REPOSITORY.git (push)
> origin https://github.com/USERNAME/REPOSITORY.git (fetch)
> origin https://github.com/USERNAME/REPOSITORY.git (push)
将oldhost.com
更改为newhost.com
,保存文件,即可完成操作
从我有限的测试(git pull origin;git push origin;gitx
)来看,一切似乎都井然有序。是的,我知道弄乱git内部是不好的
#查看现有遥控器
#起源https://github.com/user/repo.git (取回)
#起源https://github.com/user/repo.git (推)
git远程设置url源https://github.com/user/repo2.git
#更改“源”远程服务器的URL
git远程-v
#验证新的远程URL
#起源https://github.com/user/repo2.git (取回)
#起源https://github.com/user/repo2.git (推)
git-remote-v
#查看现有遥控器
#起源https://github.com/user/repo.git (取回)
#起源https://github.com/user/repo.git (推)
git远程设置url源https://github.com/user/repo2.git
#更改“源”远程服务器的URL
git远程-v
#验证新的远程URL
#起源https://github.com/user/repo2.git (取回)
#起源https://github.com/user/repo2.git (推)
(或者,打开.git/config
,查找[远程“源站”]
,然后编辑url=
行
您可以通过检查遥控器来检查它是否工作:
git remote -v
# origin git://new.location (fetch)
# origin git://new.location (push)
下次推送时,必须指定新的上游分支,例如:
git push -u origin master
另见:
(或者,打开.git/config
,查找[远程“源站”]
,然后编辑url=
行
您可以通过检查遥控器来检查它是否工作:
git remote -v
# origin git://new.location (fetch)
# origin git://new.location (push)
下次推送时,必须指定新的上游分支,例如:
git push -u origin master
另请参见:git远程设置url{name}{url}
ex)
git远程设置url源https://github.com/myName/GitTest.git
git远程设置url{name}{url}
ex)git远程设置url源https://github.com/myName/GitTest.git
在Git Bash中,输入以下命令:
git远程设置url源https://NewRepoLink.git
输入凭据
完成在Git Bash中,输入以下命令:
git远程设置url源https://NewRepoLink.git
输入凭据
完成如果您克隆了本地文件,则会自动包含 克隆它的远程URL 您可以使用
git remote-v
origin https://github.com/USERNAME/REPOSITORY.git (fetch)
origin https://github.com/USERNAME/REPOSITORY.git (push)
如果你想改变它
git remote set-url origin https://github.io/my_repo.git
这里,
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[remote "origin"]
url = [Here new url] <------------------------------------
...
git remote set-url origin git@github.com:<username>/<repo>.git
git remote set-url origin git@github.com:Chetabahana/my_repo_name.git
#!/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
#!/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
git remote set-url origin git@github.com:<username>/<repo>.git
nano .git/config
git remote -v
$ git remote rm origin
$ git remote add origin git@github.com:aplikacjainfo/proj1.git
$ git config master.remote origin
$ git config master.merge refs/heads/master
$ git remote -v
# View current remotes
> origin https://github.com/OWNER/REPOSITORY.git (fetch)
> origin https://github.com/OWNER/REPOSITORY.git (push)
> destination https://github.com/FORKER/REPOSITORY.git (fetch)
> destination https://github.com/FORKER/REPOSITORY.git (push)
$ git remote rm destination
# Remove remote
$ git remote -v
# Verify it's gone
> origin https://github.com/OWNER/REPOSITORY.git (fetch)
> origin https://github.com/OWNER/REPOSITORY.git (push)
git remote -v
> origin git@github.com:USERNAME/REPOSITORY.git (fetch)
> origin git@github.com:USERNAME/REPOSITORY.git (push)
> origin https://github.com/USERNAME/REPOSITORY.git (fetch)
> origin https://github.com/USERNAME/REPOSITORY.git (push)
$ git remote set-url origin git@github.com:USERNAME/NEW_REPOSITORY.git
$ git remote set-url origin https://github.com/USERNAME/NEW_REPOSITORY.git
export gituser='<Username>:<password>@'
git remote set-url origin https://${gituser}<gitlab_repo_url>
git push origin <Branch Name>
git remote set-url --push origin new.git.url/here
git remote set-url origin new.git.url/here
git remote set-url --push origin new.git.url/here
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]")}