Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7950715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:21:24+00:00 2026-06-04T02:21:24+00:00

I follow a development process where I create a new local branch for every

  • 0

I follow a development process where I create a new local branch for every new feature or story card. When finished I merge the branch into master and then push.

What tends to happen over time due to a combination of laziness or forgetfulness, is that I end up with a large list of local branches, some of which (such as spikes) may not have been merged.

I know how to list all my local branches and I know how to remove a single branch but I was wondering if there was a git command that allows me to delete all my local branches?

Below is the output of the git branch --merged command.

user@machine:~/projects/application[master]$ git branch --merged
  STORY-123-Short-Description
  STORY-456-Another-Description
  STORY-789-Blah-Blah
* master

All attempts to delete branches listed with grep -v \* (as per the answers below) result in errors:

error: branch 'STORY-123-Short-Description' not found.
error: branch 'STORY-456-Another-Description' not found.
error: branch 'STORY-789-Blah-Blah' not found.

I’m using:

git 1.7.4.1  
ubuntu 10.04  
GNU bash, version 4.1.5(1)-release  
GNU grep 2.5.4  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T02:21:25+00:00Added an answer on June 4, 2026 at 2:21 am

    The ‘git branch -d’ subcommand can delete more than one branch. So, simplifying @sblom’s answer but adding a critical xargs:

    git branch -D `git branch --merged | grep -v \* | xargs`
    

    or, further simplified to:

    git branch --merged | grep -v \* | xargs git branch -D 
    

    Importantly, as noted by @AndrewC, using git branch for scripting is discouraged. To avoid it use something like:

    git for-each-ref --format '%(refname:short)' refs/heads | grep -v "master\|main" | xargs git branch -D
    

    Caution warranted on deletes!

    $ mkdir br
    $ cd br; git init
    Initialized empty Git repository in /Users/ebg/test/br/.git/
    $ touch README; git add README; git commit -m 'First commit'
    [master (root-commit) 1d738b5] First commit
     0 files changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 README
    $ git branch Story-123-a
    $ git branch Story-123-b
    $ git branch Story-123-c
    $ git branch --merged
      Story-123-a
      Story-123-b
      Story-123-c
    * master
    $ git branch --merged | grep -v \* | xargs
    Story-123-a Story-123-b Story-123-c
    $ git branch --merged | grep -v \* | xargs git branch -D
    Deleted branch Story-123-a (was 1d738b5).
    Deleted branch Story-123-b (was 1d738b5).
    Deleted branch Story-123-c (was 1d738b5).
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a small software development I would like changes to follow a defined process,
My company does not follow any well defined process for software development. I want
Imagine a git repository that is structured as follows: Main branch - development for
Our setup as follows: We have a local development server running Ubuntu, with a
The thing is I'm new on iPhone and Objective C development and I'd like
I need to create a flowchart to show Developer computers, Development server, Development DB,
I'm interested in where to find information about agile software engineering development process metrics,
I have been perpetually intrigued by test-driven development, but I can never follow through
I'm trying to write an integration that tests the whole Twitter authentication process. Every
I am starting into the development of mobile app. I want to start with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.