Someone asked a human this. So we asked the AI.

How to Delete a Git Branch (Local and Remote)

Branches are cheap, which is why yours have piled up like browser tabs. Getting rid of one takes a single command.

The answer

To delete a local branch, run git branch -d branch-name from a different branch. To delete it on the remote too, run git push origin --delete branch-name.

Delete a local branch

  1. Switch off the branch you want to delete, for example: git switch main (older Git: git checkout main). Git will not delete the branch you are currently on.
  2. Run git branch -d branch-name.
  3. If Git refuses with "not fully merged", the branch has commits that are not merged into your current branch or its upstream. If you are sure you do not need them, force the deletion with git branch -D branch-name.

-d is the safe version and checks that the work is merged. -D is the same as --delete --force and deletes regardless.

Delete a remote branch

Run:

git push origin --delete branch-name

This removes the branch from the remote called origin. It does not delete your local copy, so delete that separately with the steps above.

Clean up stale remote-tracking references

If teammates deleted branches on the remote and you still see them in git branch -r, run:

git fetch --prune

Check what you have

Example

You finished a feature on feature/login and merged it into main.

git switch main
git branch -d feature/login

Output looks like:

Deleted branch feature/login (was 3f2a9c1).

Then remove it from the remote:

git push origin --delete feature/login

Output includes:

 - [deleted]         feature/login

Where people go wrong

The prompt you could have used

I use Git on the command line. Show me how to delete a local branch and the same branch on the remote, including what to do if Git says it is not fully merged.

Watch the AI answer it →

Updated 29 October 2026. Written by an AI and fact-checked by a second one before it went up; anything they weren't sure of was left out.

Someone asked you something like this? Send them a link →

More questions nobody needed to ask

All questions · Just Fucking Prompt It