e-s*_*tis 3529 git url git-remote
我在我的硬盘驱动器(本地)上克隆的USB密钥上有一个repo(origin).我将"origin"移动到NAS并成功测试从这里克隆它.
我想知道我是否可以在"本地"设置中更改"origin"的URI,因此它现在将从NAS中提取,而不是从USB密钥中提取.
现在,我可以看到两个解决方案:
将所有内容推送到usb-orign,并将其再次复制到NAS(由于对来源的新提交而意味着大量的工作);
添加一个新的遥控器到"本地"并删除旧遥控器(我担心我会打破我的历史).
hob*_*bbs 5755
您可以
git remote set-url origin new.git.url/here
Run Code Online (Sandbox Code Playgroud)
(请参阅参考资料git help remote
)或者您可以.git/config
在那里编辑和更改网址.除非你做一些非常愚蠢的事情,否则你不会有失去历史的危险(如果你担心,只要复制你的回购,因为你的回购是你的历史.)
小智 790
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)
Run Code Online (Sandbox Code Playgroud)
Mit*_*ana 118
这非常容易和简单;只需按照这些说明操作即可。
git remote set-url origin githubrepurl
Run Code Online (Sandbox Code Playgroud)
git remote show origin
Run Code Online (Sandbox Code Playgroud)
yod*_*oda 92
来自: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
Run Code Online (Sandbox Code Playgroud)
有关详细信息,请参见手册页.
如果您使用的是旧版本,请尝试以下操作:
作为一个警告,这只是因为它是相同的服务器,只是使用不同的名称.
假设新主机名是newhost.com
,而旧主机名是oldhost.com
,则更改非常简单.
编辑.git/config
工作目录中的文件.你应该看到类似的东西:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = ssh://oldhost.com/usr/local/gitroot/myproject.git
Run Code Online (Sandbox Code Playgroud)
更改oldhost.com
为newhost.com
,保存文件,您就完成了.
从我的有限测试(git pull origin; git push origin; gitx
)看来,一切都井井有条.是的,我知道混淆git内部结构是不好的形式.
小智 58
效果会很好,你可以试试这个
对于 SSH:
命令: git remote set-url origin <ssh_url>
例子: git remote set-url origin git@github.com:username/rep_name.git
对于 HTTPS:
命令: git remote set-url origin <https_url>
例子: git remote set-url origin https://github.com/username/REPOSITORY.git
Zaz*_*Zaz 50
git remote set-url origin git://new.location
Run Code Online (Sandbox Code Playgroud)
(或者,打开.git/config
,查找[remote "origin"]
和编辑该url =
行.
您可以通过检查遥控器来检查它是否有效:
git remote -v
# origin git://new.location (fetch)
# origin git://new.location (push)
Run Code Online (Sandbox Code Playgroud)
下次推送时,您必须指定新的上游分支,例如:
git push -u origin master
Run Code Online (Sandbox Code Playgroud)
另请参阅:GitHub:更改远程URL
小智 40
First you need to type this command to view existing remotes
git remote -v
Then second you need to type this command to Change the 'origin' remote's URL
git remote set-url origin <paste your GitHub URL>
Zah*_*kot 36
正如这里所见,
$ 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
Run Code Online (Sandbox Code Playgroud)
VIK*_*HLI 32
开放式终端.
Ist步骤: - 将当前工作目录更改为本地项目.
第二步: - 列出您现有的遥控器,以获取您想要更改的遥控器的名称.
git remote -v
origin https://github.com/USERNAME/REPOSITORY.git (fetch)
origin https://github.com/USERNAME/REPOSITORY.git (push)
Run Code Online (Sandbox Code Playgroud)
使用git remote set-url命令将远程的URL从HTTPS更改为SSH.
第三步: - git remote set-url origin git@github.com:USERNAME/REPOSITORY.git
第4步: - 现在验证远程URL是否已更改.
git remote -v
验证新的远程URL
origin git@github.com:USERNAME/REPOSITORY.git (fetch)
origin git@github.com:USERNAME/REPOSITORY.git (push)
Run Code Online (Sandbox Code Playgroud)
viv*_*kar 26
从您的 repo 终端编写以下命令:
git remote set-url origin git@github.com:<username>/<repo>.git
Run Code Online (Sandbox Code Playgroud)
有关更改遥控器中 url 的更多详细信息,请参阅此链接。
Sun*_*ary 21
bon*_*hoe 18
git remote set-url {name} {url}
EX) git remote set-url origin https://github.com/myName/GitTest.git
Ami*_*esh 16
故障排除 :
尝试更改遥控器时可能会遇到这些错误。没有这样的远程 '[name]'
此错误意味着您尝试更改的遥控器不存在:
git remote set-url SOFAKE https://github.com/octocat/Spoon-Knife 致命:没有这样的远程“沙发”
检查您是否正确键入了远程名称。
参考:https : //help.github.com/articles/changed-a-remote-s-url/
Sau*_*abh 15
导航到本地存储库的项目根目录并检查现有遥控器:
git remote -v
Run Code Online (Sandbox Code Playgroud)
如果您的存储库使用SSH,您将看到如下内容:
> origin git@github.com:USERNAME/REPOSITORY.git (fetch)
> origin git@github.com:USERNAME/REPOSITORY.git (push)
Run Code Online (Sandbox Code Playgroud)
如果您的存储库使用HTTPS,您将看到如下内容:
> origin https://github.com/USERNAME/REPOSITORY.git (fetch)
> origin https://github.com/USERNAME/REPOSITORY.git (push)
Run Code Online (Sandbox Code Playgroud)
更改 URL 是通过git remote set-url
. 根据 的输出git remote -v
,您可以通过以下方式更改 URL:
在的情况下,SSH,你可以更改URL REPOSITORY.git
,以NEW_REPOSITORY.git
这样的:
$ git remote set-url origin git@github.com:USERNAME/NEW_REPOSITORY.git
Run Code Online (Sandbox Code Playgroud)
而在的情况下,HTTPS,您可以更改URL REPOSITORY.git
,以NEW_REPOSITORY.git
这样的:
$ git remote set-url origin https://github.com/USERNAME/NEW_REPOSITORY.git
Run Code Online (Sandbox Code Playgroud)
注意:如果您更改了GitHub用户名,您可以按照与上述相同的过程更新与您的存储库关联的用户名的更改。你只需要更新USERNAME
的git remote set-url
命令。
Raj*_*ram 14
如果您想在原始网址中设置用户名和密码,您可以按照以下步骤操作。
将密码导出到变量中可以避免特殊字符的问题。
脚步:
export gituser='<Username>:<password>@'
git remote set-url origin https://${gituser}<gitlab_repo_url>
git push origin <Branch Name>
Run Code Online (Sandbox Code Playgroud)
小智 14
转到要更改的文件夹/存储库并执行以下命令:
以下命令将更改存储库的 git fetch url。
git remote set-url origin <your new url>.git
Run Code Online (Sandbox Code Playgroud)
以下命令将更改存储库的 git Push url。
git remote set-url --push origin <your new url>.git
Run Code Online (Sandbox Code Playgroud)
以下命令检查上述更改是否反映
git remote -v
Run Code Online (Sandbox Code Playgroud)
小智 13
要更改远程上游:
git remote set-url origin <url>
要添加更多上游:
git remote add newplace <url>
所以你可以选择在哪里工作
git push origin <branch>
或git push newplace <branch>
小智 12
移除遥控器
使用 git Remote rm 命令从存储库中删除远程 URL。
$ 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)
Run Code Online (Sandbox Code Playgroud)
Anu*_*rya 11
要检查git远程连接:
git remote -v
Run Code Online (Sandbox Code Playgroud)
现在,将本地存储库设置为远程git:
git remote set-url origin https://NewRepoLink.git
Run Code Online (Sandbox Code Playgroud)
现在使其成为上游或推送使用以下代码:
git push --set-upstream origin master -f
如果你克隆了你的本地会自动编组,
克隆它的远程URL.
你可以用它来检查 git remote -v
如果你想改变它,
git remote set-url origin https://github.io/my_repo.git
Run Code Online (Sandbox Code Playgroud)
这里,
起源 - 你的分支
如果你想覆盖现有的分支,你仍然可以使用它..它将覆盖你现有的...它会做,
git remote remove url
and
git remote add origin url
Run Code Online (Sandbox Code Playgroud)
为了你...
您可以通过编辑配置文件来更改 url。转到您的项目根目录:
nano .git/config
Run Code Online (Sandbox Code Playgroud)
然后编辑 url 字段并设置新的 url。保存更改。您可以使用该命令验证更改。
git remote -v
Run Code Online (Sandbox Code Playgroud)
另一种方法是重命名“旧”原点(在下面的示例中,我将其简单命名old-origin
)并添加一个新原点。如果您仍然希望能够时不时地推送到旧源,这可能是理想的方法:
git remote rename origin old-origin
git remote add origin git@new-git-server.com>:<username>/<projectname>.git
Run Code Online (Sandbox Code Playgroud)
如果您需要将本地状态推送到新的来源:
git push -u origin --all
git push -u origin --tags
Run Code Online (Sandbox Code Playgroud)
对我来说,接受的答案仅适用于 fetch 而不是 pull 的情况。我做了以下工作以使其也适用于推送。
git remote set-url --push origin new.git.url/here
Run Code Online (Sandbox Code Playgroud)
所以要更新获取 URL:
git remote set-url origin new.git.url/here
Run Code Online (Sandbox Code Playgroud)
要更新拉取 URL:
git remote set-url --push origin new.git.url/here
Run Code Online (Sandbox Code Playgroud)
如果您正在使用TortoiseGit,请按照以下步骤操作:
TortoiseGit -> Settings
Git -> Remote
origin
URL
文本框值更改为新远程存储库所在的位置您的分支机构和所有本地提交将保持不变,您可以像以前一样继续工作.
您有很多方法可以做到这一点:
安慰
git remote set-url origin [Here new url]
Run Code Online (Sandbox Code Playgroud)
只需确保已在存储库所在的位置将其打开即可。
设定档
它放置在.git / config(与存储库相同的文件夹)中
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[remote "origin"]
url = [Here new url] <------------------------------------
...
Run Code Online (Sandbox Code Playgroud)
龟龟
然后,只需编辑URL。
源树
单击工具栏上的“设置”按钮以打开“存储库设置”窗口。
单击“添加”以将远程存储库路径添加到存储库。将打开“远程详细信息”窗口。
输入远程路径的名称。
输入远程存储库的URL /路径
输入远程存储库的托管服务的用户名。
单击“确定”添加远程路径。
返回“存储库设置”窗口,单击“确定”。现在应该在存储库中添加新的远程路径。
如果您需要编辑已经添加的远程路径,只需单击“编辑”按钮。应该将您定向到“远程详细信息”窗口,您可以在其中编辑远程路径的详细信息(URL /路径/主机类型)。
要删除远程存储库路径,请单击“删除”按钮
参考 支持
检查你的特权
就我而言,我需要检查我的用户名
我有两个或三个具有单独凭据的存储库。
问题是我的许可我有两个私人 git 服务器和存储库
第二个帐户是新存储库的管理员,第一个帐户是我的默认用户帐户,我应该向第一个帐户授予权限
将远程git URI更改为
git@github.com
而不是https://github.com
git remote set-url origin git@github.com:<username>/<repo>.git
Run Code Online (Sandbox Code Playgroud)
例:
git remote set-url origin git@github.com:Chetabahana/my_repo_name.git
Run Code Online (Sandbox Code Playgroud)
好处是您可以在使用ssh-agent时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
Run Code Online (Sandbox Code Playgroud)
放置一个脚本文件$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
Run Code Online (Sandbox Code Playgroud)
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]")}
Run Code Online (Sandbox Code Playgroud)
这个答案与我在其他地方找不到答案的问题有关:为 Gitlab 中的一个项目执行此操作,该项目有一个子组。这确实通过 SSH 起作用:
git remote add origin git@gitlab.com:group/subgroup/project.git
Run Code Online (Sandbox Code Playgroud)
与所有使用“用户名”而不是“组”的答案相比,这些答案都没有通过 SSH 对我有用。或者,通过 https 实现的方法:
git remote add origin https://username@gitlab.com/group/subgroup/project.git
Run Code Online (Sandbox Code Playgroud)
请注意“.com:group”和“.com/group”两者的区别
如果这不能立即工作,我在成功使用 SSH 方法之前使用了 HTTPS 方法,这可能是一个因素,但我不能在没有它的情况下尝试复制它。