• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (deprecated)
You are here: Home / Dev Tips / Git delete remote branch

Git delete remote branch

Last updated on April 25, 2023 by Sal Ferrarello

This is the command I run when I want to delete a branch named chore/fix-typo from the default remote (which is named origin): git push origin --delete chore/fix-typo

Making My Life Easier

Typically when I want to delete a remote branch, I want to delete the branch on the remote named origin with the same name as the local branch I’m currently on. To make my life easier I’ve setup a Git alias to do this when I type git drb, for “d(elete) r(emote) b(ranch)”.

You can add this alias by running the following from the command line:

git config --global alias.drb '!git push origin --delete $(git rev-parse --abbrev-ref HEAD)'

After running the above command git drb will work for you and if you look in your Git config (~/.gitconfig), you’ll see a section that looks like

[alias]
    drb = !git push origin --delete $(git rev-parse --abbrev-ref HEAD)

An Example

For example, if I’m on the branch chore/fix-typo, I want to delete the branch on the remote origin named chore/fix-typo.

In this situation, running git drb will behave the same as running git push origin --delete chore/fix-typo

How this Alias Works

The alias runs git push origin --delete followed by the current branch name (see Git Get Current Branch Name for more information on how this works).

Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP and JavaScript developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a principal engineer.

Filed Under: Dev Tips, Solution Tagged With: Git, git alias

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2026 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in