如何在 Windows 上更改远程/目标存储库 URL?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1800859/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I change the remote/target repository URL on Windows?
提问by user169320
I created a local GIT repository on Windows. Let's call it AAA. I staged, committed, and pushed the contents to GitHub. [email protected]:username/AAA.git
我在 Windows 上创建了一个本地 GIT 存储库。我们称之为AAA。我上演、提交并将内容推送到 GitHub。[email protected]:username/AAA.git
I realized I made a mistake with the name.
我意识到我弄错了名字。
On GitHub, I renamed it to [email protected]:username/BBB.git
在 GitHub 上,我将其重命名为 [email protected]:username/BBB.git
Now, on my Windows machine, I need to change [email protected]:username/AAA.git
to [email protected]:username/BBB.git
because the settings are still trying to "push" to [email protected]:username/AAA.git
but I need to push to [email protected]:username/BBB.git
now.
现在,在我的 Windows 机器上,我需要更改[email protected]:username/AAA.git
为,[email protected]:username/BBB.git
因为设置仍在尝试“推送”到,[email protected]:username/AAA.git
但我[email protected]:username/BBB.git
现在需要推送到。
How could I do that?
我怎么能那样做?
采纳答案by jkp
The easiest way to tweak this in my opinion (imho) is to edit the .git/config file in your repository. Look for the entry you messed up and just tweak the URL.
在我看来,最简单的调整方法(恕我直言)是编辑存储库中的 .git/config 文件。查找您搞砸的条目并调整 URL。
On my machine in a repo I regularly use it looks like this:
在我的机器上,我经常使用它看起来像这样:
KidA% cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
autocflg = true
[remote "origin"]
url = ssh://localhost:8888/opt/local/var/git/project.git
#url = ssh://xxx.xxx.xxx.xxx:80/opt/local/var/git/project.git
fetch = +refs/heads/*:refs/remotes/origin/*
The line you see commented out is an alternative address for the repository that I sometimes switch to simply by changing which line is commented out.
您看到注释掉的行是存储库的替代地址,我有时只需更改注释掉的行即可切换到该地址。
This is the file that is getting manipulated under-the-hood when you run something like git remote rm
or git remote add
but in this case since its only a typo you made it might make sense to correct it this way.
当您运行类似git remote rm
或的文件时,这是在后台被操纵的文件,git remote add
但在这种情况下,因为它只是一个错字,因此以这种方式更正它可能是有意义的。
回答by hallucinations
git remote set-url origin <URL>
回答by Abibullah Rahamathulah
One more way to do this is:
另一种方法是:
git config remote.origin.url https://github.com/abc/abc.git
To see the existing URL just do:
要查看现有 URL,只需执行以下操作:
git config remote.origin.url
回答by Steinbitglis
Take a look in .git/config and make the changes you need.
查看 .git/config 并进行所需的更改。
Alternatively you could use
或者你可以使用
git remote rm [name of the url you sets on adding]
and
和
git remote add [name] [URL]
Or just
要不就
git remote set-url [URL]
Before you do anything wrong, double check with
在你做错任何事之前,请仔细检查
git help remote