1

First, I've found other questions on cleaning up old branches on remotes.

What I'd really like is a command that looks for all branches that are merged and older than some threshold (say 2 weeks). Then deletes that local and remote branch.

Any ideas on how to do that?

Mat Schaffer
  • 1,634
  • 1
  • 15
  • 24
  • 1
    Does this answer your question? [How can I delete all Git branches which have been merged?](https://stackoverflow.com/questions/6127328/how-can-i-delete-all-git-branches-which-have-been-merged) – Michael Freidgeim Dec 25 '20 at 02:48

1 Answers1

5

Be interesting to see what other say - since I am not a git expert - but you do have these options.

First find a commit which is two weeks old

git log -n 1 --format="%h %aD" --until="@{2 weeks ago}"
b4f2ff3 Fri, 28 Oct 2011 08:36:56 -0600

Show unmerged branches since that commit

git branch --no-merged b4f2ff3
  foo
* master
  views_to_tables

Show merged branches since that commit

git branch --merged b4f2ff3
  Hday.mt
  commod_stat
  commodity_stat_SP
  merged
  printscheman
  program_options
  release
  test

Delete local branch

git branch -d <branchname>

Delete remote branch

git push origin :<branchname>
Adrian Cornish
  • 23,227
  • 13
  • 61
  • 77