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

  • SEARCH
  • Home
  • 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 630229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:49:58+00:00 2026-05-13T19:49:58+00:00

If you do git branch -d branchname , it will delete branch name if

  • 0

If you do git branch -d branchname, it will delete branch name if it references an earlier commit in your history, or tell you that you need to use -D otherwise. I often create branches that are later pushed to master, and can thus be deleted by this criterion. Is there an easy way to list all the branches that point to earlier commits of master, that is, branches that git will not mind deleting with just the -d option? Bonus points if it works for all branches at once, not just master.

I’ve got 82 local branches and I know that quite a few if not most of them can safely be deleted by now, but I don’t want to take the time to go through each one to try to do it.

  • 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-05-13T19:49:58+00:00Added an answer on May 13, 2026 at 7:49 pm

    Try:

    $ git checkout master # or whatever branch you might compare against ...
    $ git branch --no-merged
    $ git branch --merged
    

    From git branch documentation:

    With –merged, only branches merged into the named commit (i.e. the branches whose tip commits are reachable from the named commit) will be listed. With –no-merged only branches not merged into the named commit will be listed. If the argument is missing it defaults to HEAD (i.e. the tip of the current branch).

    EDIT:

    to show this for every branch, you could do something like this:

    example repo:

    o <--- experimental
    |
    o
    |
    o <--- next
    |
    o
    |
    o <--- master
    |
    o----o <--- broken
    |
    o
    |
    
    
    $ for branch in `git branch --no-color --verbose | \
    sed -e 's/*//' | awk '{print $1}'`; \
    do echo "[$branch]"; git checkout -q $branch; git branch --merged; done
    
    [broken]
    * broken
    [master]
    * master
    [next]
    master
    * next
    [experimental]
    master
    next
    * experimental
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help with a Bash script that will automatically add the git's
I have a git branch that is based off an old master. This branch
The command git branch -a lists a bunch of branches that are NOT on
When I try to push to a remote git branch to delete it with
I'd like to delete a remote branch from my central git repository. The usual
In Git, what does deletion of a branch mean? Will it be gone from
I have a branch that I'd like to move into a separate Git repository,
I just deleted the wrong branch with some experimental changes I need with git
I am very new to git but I need to use it for one
I need to do several two-step or three-step commands in Git quite frequently, that

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.