如何在Windows上更改远程/目标存储库URL?

时间:2009-11-26 00:14:39

标签: windows git github

我在Windows上创建了一个本地GIT存储库。我们称之为AAA。我上传,提交并将内容推送到GitHub。 git@github.com:username/AAA.git

我意识到我的名字出错了。

在GitHub上,我将其重命名为git@github.com:username/BBB.git

现在,在我的Windows计算机上,我需要将git@github.com:username/AAA.git更改为git@github.com:username/BBB.git,因为设置仍在尝试“推送”到git@github.com:username/AAA.git,但我需要推送到{{1}现在。

我怎么能这样做?

4 个答案:

答案 0 :(得分:264)

git remote set-url origin <URL>

答案 1 :(得分:122)

在我看来(imho)调整此最简单的方法是编辑存储库中的.git / config文件。查找您搞砸的条目,只需调整URL。

在我的机器上的回购中,我经常使用它看起来像这样:

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/*

您看到注释掉的行是存储库的替代地址,我有时会通过更改注释掉的行来切换到该地址。

当您运行类似git remote rmgit remote add的内容时,这个文件会在幕后进行操作,但在这种情况下,因为它只是一个错字,所以它可能有意义来纠正它这样。

答案 2 :(得分:57)

另一种方法是:

git config remote.origin.url https://github.com/abc/abc.git

要查看现有网址,请执行以下操作:

git config remote.origin.url

答案 3 :(得分:23)

查看.git / config并进行所需的更改。

或者你可以使用

git remote rm [name of the url you sets on adding]

git remote add [name] [URL]

或者只是

git remote set-url [URL]

在你做错之前,请仔细检查

git help remote