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?
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 .
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.
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 .
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With