Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I delete a branch from GitHub?

Tags:

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?

like image 474
user1356397 Avatar asked Apr 25 '12 14:04

user1356397


People also ask

How do I delete a remote branch in GitHub?

To delete a remote branch, you can't use the git branch command. Instead, use the git push command with --delete flag, followed by the name of the branch you want to delete. You also need to specify the remote name ( origin in this case) after git push .

How do I remove a branch from a git project?

If you remove the Git branch locally, there will still be a remote tracking branch in your repository's list of local branches. Here is the Git command to remove a local tracking branch: git branch --remotes --delete origin/name-of-branch-to-remove. git branch -r -d origin/name-of-branch-to-remove.

How do I delete unwanted branches?

Use git prune to remove orphaned/unused branches If you see any branches in there that you don't want, you can use the command git branch -d <branch name> . If you want to delete the branch called badbranch, use the -D switch to force the deletion if it doesn't work: git branch -d badbranch .

How do I delete a branch after merge in GitHub?

On GitHub.com, navigate to the main page of the repository. Under your repository name, click Settings. Under "Pull Requests", select or unselect Automatically delete head branches.


1 Answers

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.

like image 191
Michael Wild Avatar answered Sep 21 '22 14:09

Michael Wild