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

use*_*320 126 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.gitgit@github.com:username/BBB.git因为设置仍在尝试"推送" git@github.com:username/AAA.git但我需要推送到git@github.com:username/BBB.git现在.

我怎么能这样做?

hal*_*ons 265

git remote set-url origin <URL>
Run Code Online (Sandbox Code Playgroud)

  • 这似乎工作正常.但是,如果您要将现有仓库复制到新仓库,则需要使用git push origin master进行跟进. (7认同)

jkp*_*jkp 124

在我看来(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/*
Run Code Online (Sandbox Code Playgroud)

您看到注释掉的行是存储库的替代地址,我有时只需更改注释掉的行即可切换到该地址.

当你运行类似的东西git remote rm或者git remote add在这种情况下运行时,这个文件会在引擎盖下进行操作,因为它只是一个错字,你可以通过这种方式纠正它.


Abi*_*lah 59

另一种方法是:

git config remote.origin.url https://github.com/abc/abc.git
Run Code Online (Sandbox Code Playgroud)

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

git config remote.origin.url
Run Code Online (Sandbox Code Playgroud)


Ste*_*lis 24

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

或者你可以使用

git remote rm [name of the url you sets on adding]
Run Code Online (Sandbox Code Playgroud)

git remote add [name] [URL]
Run Code Online (Sandbox Code Playgroud)

要不就

git remote set-url [URL]
Run Code Online (Sandbox Code Playgroud)

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

git help remote
Run Code Online (Sandbox Code Playgroud)

  • git remote set-url {new url} (3认同)