Home git How do I delete a Git branch both locally and remotely?

How do I delete a Git branch both locally and remotely?




I want to delete a branch both locally and remotely from a project on GitHub.

Deleted locally

& gt; git branch -D feature / experiment
& gt; Deleted branch feature / experiment (was 863225e).

Attempts to delete a branch on the server

& gt; git branch -d origin / feature / experiment
error: branch 'origin / feature / experiment' not found.
& gt; git branch -rd origin / feature / experiment
Deleted remote branch origin / feature / experiment (was 863225e).
& gt; git pull
* [new branch] feature / experiment - & gt; origin / feature / experiment

It’s not clear what “Deleted remote branch” means if the branch has not actually been deleted? The subsequent pull command shows this.

What do I need to do to remove a branch both locally and on the server?

Answer 1, authority 100%

In Git v1.7.0, you can delete a remote branch using

git push origin --delete & lt; branchName & gt;

which is easier to remember than

git push origin: & lt; branchName & gt;

added in Git v1.5.0 “to remove a remote branch or tag”.


Answer 2, authority 7%

You can delete a branch in the remote repository like this:

git push origin: feature / experiment

-rd doesn’t work because it only removes the local remote-tracking branch. If the corresponding branch has not been removed from the remote repository, the remote-tracking branch will be recreated the next time the fetch command is invoked.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions