我错误地在命令行中将一个未知的存储库添加到 git 本地如何删除或替换存储库

问题描述

我想删除错误的存储库并将其替换为 GitHub 上的正确存储库。我该怎么办?

Fatal: repository "https://GitHub.com/username/alx-pre_school.git" not found

解决方法

很可能您已将存储库命名为 origin,您可以通过运行来检查它

git remote -v

输出看起来像

origin  https://github.com/user/your_repo.git (fetch)
origin  https://github.com/user/your_repo.git (push)

要更改远程的存储库 URL,请运行

git remote set-url origin https://github.com/user/new_name.git
,

您可以简单地执行以下命令来更改 URI:

  • HTTPS

    git remote set-url origin https://github.com/USERNAME/REPOSITORY.git

  • SSH

    git remote set-url origin git@github.com:USERNAME/REPOSITORY.git

或者,在克隆的文件夹结构中找到 .git/config,查找 [remote "origin"],然后编辑 url = 分配。

.git/config 看起来与下面类似,

[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = https://github.com/USERNAME/REPOSITORY.git

通过检查遥控器来验证它是否工作:

git remote -v
# origin  git://new.location (fetch)
# origin  git://new.location (push)

下次推送时,提及上游,如下所示:

git push -u origin master

参考:GitHub: Manage Remote repositories