0

If I check my local git branches.

$ git branch
  local-feat-18.3-APPLE-1854-20180227
  local-feat-18.3-APPLE-1854-20180227#1
  local-feat-18.3-APPLE-1854-20180228
  local-feat-18.3-APPLE-1854-20180228#1
  local-feat-18.3-APPLE-1899-20180320
  local-feat-18.3-APPLE-1899-20180320#1
  local-feat-18.3-APPLE-1899-20180320#2
  local-feat-18.3-APPLE-1899-20180330
  local-feat-18.3-APPLE-1899-20180330#1
  local-feat-18.3-APPLE-1921-20180402
  local-feat-18.3-APPLE-1921-20180402#2
  local-feat-18.3-APPLE-1921-20180402#3

After deletion, it will look like below:

$ git branch
  local-feat-18.3-APPLE-1899-20180320
  local-feat-18.3-APPLE-1899-20180320#1
  local-feat-18.3-APPLE-1899-20180320#2
  local-feat-18.3-APPLE-1899-20180330
  local-feat-18.3-APPLE-1899-20180330#1
  local-feat-18.3-APPLE-1921-20180402
  local-feat-18.3-APPLE-1921-20180402#2
  local-feat-18.3-APPLE-1921-20180402#3

Would you please help me to fix the issue. Thanks in advance for your kind support.

I don't consider, is it merged or not. I have go through stackoverflow. I got some suggestions like below, but not satisfied.

  1. To delete every branch except the one that you currently have checked out:

    for b in `git branch --merged | grep -v \*`; do git branch -D $b; done
    
  2. The simpler way to delete all branches but keeping others like "develop" and "master" is the following:

    git branch | grep -v "develop" | grep -v "master" | xargs git branch -D
    

Resource Link: Delete all local git branches

SkyWalker
  • 28,384
  • 14
  • 74
  • 132

2 Answers2

2

Whilst I haven't personally tested this, your comment suggests it was successful.

Essentially your second suggestion removed develop and master from a git branch output.

My thought was to reverse the filter, so that grep only included the branches with the name you were after.

git branch | grep "local-feat-18.3-APPLE-1854" | xargs git branch -D

My simple explanation is as follows:

  • git branch outputs a list of all local existing branches.
  • | grep "mystring" pipe the output into a grep search and only select the lines which contain "mystring".
  • | xargs git branch -D pipe that output as a set of arguments and delete the branches.
evolutionxbox
  • 3,932
  • 6
  • 34
  • 51
1

You can test by this git command.

git branch -D `git branch | grep -E '^3\.2\..*'`

Resource Link: https://stackoverflow.com/a/3670479