Reputation: 1237
I'm trying to remove a remote git repository through Git Bash. I'm aware that I can just delete it through GitHub; however, I want to learn how to do so through the command line. I don't just want to remove the files in it, or replace it, I want to completely delete it. I spent the last two days sifting through forums, articles, blogs and tutorials, and nothing has worked.
Some initial info:
$ 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)
Some things I tried:
$ 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*
I've realized I also never get returned the name 'origin'.
Upvotes: 17
Views: 35037
Reputation: 66183
As pointed out by BrokenBinary in his comment,
This can't be done.
You cannot delete a remote repo (hosted on GitHub or elsewhere) with Git commands, be it in Git Bash or elsewhere, period. You can delete remote branches (assuming you have write access to them), yes, but not an entire remote repository.
However, the GitHub Developer API allows you to delete, at the command line, a repo hosted on GitHub.
Upvotes: 14
Reputation: 21
Yes, you can delete the repository.
First we need to add repository:
git remote add origin <repository link>
If we want to delete repository:
git remote remove origin
then press enter button
Upvotes: 2
Reputation: 19
First, switch to sudo mode:
gh auth refresh -h github.com -s delete_repo
After the signup, then you can:
gh repo delete
Note: This only deletes the remote repository. To delete it locally, go to the parent directory and use the command rm -r dirname
; replace dirname
with the name of your directory.
Upvotes: 1
Reputation: 1323115
This now (Oct. 2021) can be done from command-line, using gh repo delete
, added in the GitHub CLI gh
2.2.0
This is from the feature request 3625 (Add feature to delete a repository from command line), fixed in PR 4451, and commit 5a3b9ce.
It does wrap the curl -u :username -X "DELETE" https://api.github.com/repos/:username/:repo
mentioned in daGo's 2017 answer.
Upvotes: 1
Reputation: 2968
As Jubobs mentioned above you can use github dev API, so:
curl -u :username -X "DELETE" https://api.github.com/repos/:username/:repo
Where :username = your username(github handler) and :repo = a name of a repo you want to get rid of
Upvotes: 8