user1356397
user1356397

Reputation: 103

How do I delete a branch from GitHub?

I saw previous posts asking about this, but none that solved it for me. I don't use Git through the command line, I use it as it's integrated into Xcode. I created a branch and pushed it to GitHub, and now I want to delete it. I deleted it in Xcode, but it's still on GitHub. The GitHub directions say to just go to Admin and delete the repo, but there it says it'll delete the whole project, not just the branch. So what am I missing?

Upvotes: 10

Views: 5469

Answers (1)

Michael Wild
Michael Wild

Reputation: 26341

You want to delete a branch on github? Just do

$ git push origin :branch-name

where you have to substitute origin with the name of the remote repository and branch-name with the name of the branch you want to delete at github.

Edit: Note the colon in front of the branch name, it is important.

Edit 2: To be more verbose:

$ cd /path/to/local/git/checkout
$ git remote -v show

Pick the remote name from the first column which corresponds to the github URL where you want to delete the branch. I call it origin here. branch-name is the name of the branch you want to delete. Delete it using:

$ git push origin :branch-name

Edit 3: If you want to learn about git, I can recommend the free book by Scott Chacon. The relevant section is here.

Upvotes: 16

Related Questions