【问题标题】:How can I delete a remote Git repository from the command line (Git Bash)?如何从命令行 (Git Bash) 删除远程 Git 存储库?
【发布时间】:2015-03-08 06:00:51
【问题描述】:

我正在尝试通过 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*

我意识到我也永远不会得到“起源”这个名字。

【问题讨论】:

标签: git github repository


【解决方案1】:

正如 BrokenBinary 在his comment 中指出的那样,

这是做不到的。

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

但是,GitHub Developer API 允许您从 shell 中删除托管在 GitHub 上的存储库。

【讨论】:

  • 感谢@BrokenBrinary 和 Jubobs。我想我会直接从 GitHub 站点删除 repos。
【解决方案2】:

正如上面提到的 Jubobs,你可以使用 github dev API,所以: curl -u :username -X "DELETE" https://api.github.com/repos/:username/:repo 其中 :username = 您的用户名(github 处理程序)和 :repo = 您要删除的 repo 的名称

【讨论】:

  • 当您浏览“github.com/${username}/${repo}/settings/delete”时,我的 Web 浏览器与 GitHub 使用的 Javascript 存在问题。我尝试使用此答案推荐的 API,我的删除成功、轻松且没有问题。
【解决方案3】:

要从 cmd 行删除远程仓库,可以使用以下命令

git push origin --delete remote-reponame

【讨论】:

  • 这是错误的,只能用来删除远程分支。
【解决方案4】:

现在(2021 年 10 月)可以在命令行中使用 gh repo delete 完成此操作,添加到 GitHub CLI gh 2.2.0

这是来自feature request 3625(添加从命令行删除存储库的功能),在PR 4451commit 5a3b9ce 中修复。

它确实包装了daGo 2017 年answer 中提到的curl -u :username -X "DELETE" https://api.github.com/repos/:username/:repo

【讨论】:

    猜你喜欢
    • 2015-10-19
    • 2012-11-28
    • 2017-08-15
    • 1970-01-01
    • 2012-08-31
    • 2013-02-21
    • 2013-02-10
    • 2014-11-19
    相关资源
    最近更新 更多