How to Delete a git Remote Branch

By  on  

Keeping a tidy repository is important; not just a tidy codebase, but a tidy repository in as far as not having spare branches rotting around.  Generally the main repository doesn't keep multiple branches but sometimes you need to push to a main repository simply to get Travis CI to run tests.  Once a branch is merged, for example, we no longer need it around.

Deleting a branch on a local host machine repo is easy:

git branch -d <branch_name>

To remove a branch from the remote git repository, like a GitHub-hosted repository, you can execute:

git push <remote_name> --delete <branch_name>

If you learned something here, check out Delete Merged Branches with git!

Recent Features

  • By
    Responsive and Infinitely Scalable JS Animations

    Back in late 2012 it was not easy to find open source projects using requestAnimationFrame() - this is the hook that allows Javascript code to synchronize with a web browser's native paint loop. Animations using this method can run at 60 fps and deliver fantastic...

  • By
    Write Better JavaScript with Promises

    You've probably heard the talk around the water cooler about how promises are the future. All of the cool kids are using them, but you don't see what makes them so special. Can't you just use a callback? What's the big deal? In this article, we'll...

Incredible Demos

  • By
    Checkbox Filtering Using MooTools ElementFilter

    When I first wrote MooTools ElementFilter, I didn't think much of it. Fast forward eight months later and I've realized I've used the plugin a billion times. Hell, even one of the "big 3" search engines is using it for their maps application.

  • By
    Elegant Overflow with CSS Ellipsis

    Overflow with text is always a big issue, especially in a programmatic environment. There's always only so much space but variable content to add into that space. I was recently working on a table for displaying user information and noticed that longer strings were...

Discussion

  1. It is even easier to delete a remote branch!

    git push origin :BRANCH_NAME

    Note the colon before the branch.

  2. You can also do

    git push :BRANCH_NAME

    – Note the colon, that states to delete the remote branch!

    • So it seems like it parsed my placeholders as HTML;

      git push origin :develop
      

      Would delete develop branch on the origin remote.

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!