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

问题描述 投票:0回答:5

我正在尝试通过 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”这个名字。

git github repository
5个回答
14
投票

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

这是做不到的。

您无法使用 Git 命令删除远程存储库(托管在 GitHub 或其他地方),无论是在 Git Bash 还是其他地方。是的,您可以删除远程分支(假设您对它们有写访问权限),但不能删除整个远程存储库。

但是,GitHub Developer API 允许您在命令行删除 GitHub 上托管的存储库。


8
投票

正如 Jubobs 上面提到的,你可以使用 github dev API,所以:

curl -u :username -X "DELETE" https://api.github.com/repos/:username/:repo
其中 :username = 您的用户名(github 处理程序)和 :repo = 您想要删除的存储库的名称


0
投票

现在(2021 年 10 月)可以使用

gh repo delete
从命令行完成此操作,已添加到 GitHub CLI
gh
2.2.0

这来自 功能请求 3625(添加从命令行删除存储库的功能),已在 PR 4451 中修复,并提交 5a3b9ce

它确实包含了

daGo
的2017年答案中提到的curl -u :username -X "DELETE" https://api.github.com/repos/:username/:repo


0
投票

首先,切换到 sudo 模式:

gh auth refresh -h github.com -s delete_repo

注册后,您可以:

gh repo delete

注意:这只会删除远程存储库。要在本地删除它,请转到父目录并使用命令

rm -r dirname
;将
dirname
替换为您的目录名称。


0
投票

是的,您可以删除存储库。

首先我们需要添加存储库:

git remote add origin <repository link>

如果我们想删除存储库:

git remote remove origin 

然后按输入按钮

© www.soinside.com 2019 - 2024. All rights reserved.