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 5965985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:43:32+00:00 2026-05-22T19:43:32+00:00

How do I delete branches which have already been merged? Can I delete them

  • 0

How do I delete branches which have already been merged? Can I delete them all at once, instead of deleting each branch one-by-one?

  • 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-22T19:43:33+00:00Added an answer on May 22, 2026 at 7:43 pm

    NOTE: You can add other branches to exclude like master and dev if your workflow has those as a possible ancestor. Usually I branch off of a "sprint-start" tag and master, dev and qa are not ancestors.


    First, list locally-tracking branches that were merged in remote (consider using -r flag to list all remote-tracking branches).

    git branch --merged
    

    You might see few branches you don’t want to remove. We can add few arguments to skip important branches that we don’t want to delete like master or a develop. The following command will skip master branch and anything that has dev in it.

    git branch --merged| grep -Ev "(^\*|master|main|dev)"
    

    If you want to skip, you can add it to the egrep command like the following. The branch skip_branch_name will not be deleted.

    git branch --merged| grep -Ev "(^\*|master|main|dev|skip_branch_name)"
    

    To delete all local branches that are already merged into the currently checked out branch:

    git branch --merged | grep -Ev "(^\*|master|main|dev)" | xargs git branch -d
    

    You can see that master and dev are excluded in case they are an ancestor.


    You can delete a merged local branch with:

    git branch -d branchname
    

    If it’s not merged, use:

    git branch -D branchname
    

    To delete it from the remote use:

    git push --delete origin branchname
    
    git push origin :branchname    # for really old git
    

    Once you delete the branch from the remote, you can prune to get rid of remote tracking branches with:

    git remote prune origin
    

    or prune individual remote tracking branches, as the other answer suggests, with:

    git branch -dr branchname
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I delete multiple branches all at once based on age of the
Once you have finished/reintegrated a branch, is it best practice to delete the branch
We have a TFS 2008 project with two branches (Main and NewFeature). Each is
How can you merge two branches in git, retaining necessary files from a branch?
I have a Database containes information about all the branches of our company around
I have a repo that I have a master branch which will end up
One of the products which I have been working started some 10 years back.
I can delete remote branches in Git using git push . (See How do
Is there command which can show me list of all available commands in GIT?
I need to delete old and unmaintained branches from our remote repository. I'm trying

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.