[英]How can I delete a remote Git repository from the command line (Git Bash)?
我正在嘗試通過 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*
我意識到我也從來沒有得到過“起源”這個名字。
正如 BrokenBinary 在他的評論中指出的那樣,
這是做不到的。
您不能使用 Git 命令刪除遠程存儲庫(托管在 GitHub 或其他地方),無論是在 Git Bash 還是其他地方。 您可以刪除遠程分支(假設您對它們具有寫入權限),是的,但不能刪除整個遠程存儲庫。
但是, GitHub Developer API允許您從 shell 中刪除托管在 GitHub 上的存儲庫。
正如上面提到的 Jubobs,您可以使用 github dev API,因此: curl -u :username -X "DELETE" https://api.github.com/repos/:username/:repo
where :username = your username(github handler)和:repo = 你想要刪除的 repo 的名稱
要從 cmd 行刪除遠程 repo,可以使用以下命令
git push origin --delete remote-reponame
現在(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
。
首先,切換到 sudo 模式:
gh auth refresh -h github.com -s delete_repo
注冊后,您可以:
gh repo delete
注意:這只會刪除遠程存儲庫。 要在本地刪除它,請轉到父目錄並使用命令rm -r dirname
; 將dirname
替換為您的目錄名稱。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.