0

I am working in git-flow based environment. We (along with team) decided not to remove remote branches for some time. How can I remove all feature branches from my remote that have no commits for last X days. I guess it can be some oneliner?

According to: How can I get a list of git branches, ordered by most recent commit? I can get branches sorted by last commit date.

And here: How to clone all remote branches in Git? I can clone all remote branches.

Can I avoid pulling all remote branches for such cleanup?

Community
  • 1
  • 1
Fishman
  • 1,737
  • 1
  • 25
  • 42

1 Answers1

1

You can avoid pulling all remote branches.

This will give you all remote feature branches, sorted by commiterdate and it will display the date of the last commit, who was the committer and the shortname of the branch.

git for-each-ref --sort=-committerdate refs/remotes/origin/feature --format='%(committerdate:short) %(authorname) %(refname:short)'

or you can show the committerdate relative to today

git for-each-ref --sort=-committerdate refs/remotes/origin/feature --format='%(committerdate:relative) %(authorname) %(refname:short)'

all you have to do is select which branches you wanted to delete and do so.

git push origin :feature/newfeature

Creating a oneliner might be possible, but I think it would be easier to just write a small script in whatever language you prefer.

Peter van der Does
  • 14,018
  • 4
  • 38
  • 42