如何从命令行(Git Bash)中删除远程Git存储库?

15

我正在尝试通过 Git Bash 删除一个远程 git 仓库。我知道我可以直接通过 GitHub 删除它;但是,我想学习如何通过命令行删除它。我不只是想删除其中的文件或替换它,我想彻底删除它。我花了过去两天的时间在论坛、文章、博客和教程中查找,但没有任何有效的解决方法。

一些初始信息:

$ git remote -v
thisbranch https://github.com/thisuser/test-repo.git (fetch)
thisbranch https://github.com/thisuser/test-repo.git (push)

$ git status
On branch master
nothing to commit, working directory clean

$ git log
Author: *info*
Date: *info*
   adding a new file
Author: *info*
Date: *info*
   Initial commit

$ git remote -v show thisbranch
* remote thisbranch
  Fetch URL: https://github.com/thisuser/test-repo.git
  Push URL: https://github.com/thisuser/test-repo.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local ref configured for 'git push':
    master pushes to master (up to date)

我尝试过的一些事情:

$ git remote remove https://github.com/thisuser/test-repo.git
error: Could not remove config section 'remote.https://github.com/thisuser/test-repo.git'

$ git remote remove master
error: Could not remove config section 'remote.master'

$ git remote remove thisbranch
*returns nothing*

$ git remote -v
*returns nothing*

我意识到我也从未收到名称为“origin”的返回值。


在2021年10月,现在有gh repo delete:请参见我的下面的答案 - VonC
5个回答

12

正如BrokenBinary在他的评论中指出的那样,

这是不可能完成的。

你无法使用Git命令(无论是在Git Bash还是其他地方)删除远程存储库(托管在GitHub或其他地方),就是这样。你可以删除远程分支(假设你有写入权限),但不能删除整个远程存储库。

然而,GitHub开发者API允许你从shell中删除托管在GitHub上的存储库。


8

如Jubobs所述,您可以使用Github Dev API,因此: curl -u :username -X“DELETE”https://api.github.com/repos/:username/:repo 其中:username =您的用户名(github处理程序),: repo =您想要摆脱的repo的名称。


0

首先,切换到 sudo 模式:

gh auth refresh -h github.com -s delete_repo

注册后,您可以:

gh repo delete

注意:此操作仅会删除远程代码库。如需在本地删除,请前往父目录并使用命令rm -r dirname,将dirname替换为您的目录名称。


0

0
是的,你可以删除仓库。
首先,我们需要添加仓库:
git remote add origin <repository link>

如果我们想要删除存储库:
git remote remove origin 

然后按下回车键

这并没有给出问题的答案。一旦你拥有足够的声望,你就能够评论任何帖子;相反地,提供不需要提问者澄清的答案。 - 来自评论审核 - user12256545

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接