Skip to content

ACTIN-3460: Add script to clean git branches#140

Merged
matt-froggatt merged 3 commits intomasterfrom
ACTIN-3460
Apr 10, 2026
Merged

ACTIN-3460: Add script to clean git branches#140
matt-froggatt merged 3 commits intomasterfrom
ACTIN-3460

Conversation

@matt-froggatt
Copy link
Copy Markdown
Contributor

Wrote this to delete stale branches on my local git, added it to scripts because I felt it might be useful to someone else.

Copy link
Copy Markdown
Contributor

@nedleitch nedleitch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine, I might call it git-clean-stale-branches or something similarly more-descriptive.

#!/usr/bin/env bash

git fetch --prune
mapfile -t MERGED_DELETED_BRANCHES < <(git branch -vv | grep ': gone]' | awk '{print $1}')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit here, I don't think you need the <(...) construct, which presents a file descriptor for the given command output, because mapfile is meant to take stdin. In fact I thought you had to specify -u for that?

While this may (or may not...) work, I'd expect to see either:

git branch -vv | grep ': gone]' | awk '{print $1}' | mapfile -t MERGED_DELETED_BRANCHES

or

mapfile -t MERGED_DELETED_BRANCHES < $(git branch ...)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems I can't use mapfile -t MERGED_DELETED_BRANCHES < $(git branch ...) since < to redirect to stdin expects a file descriptor, and I can't use git branch -vv | grep ': gone]' | awk '{print $1}' | mapfile -t MERGED_DELETED_BRANCHES because it scopes the MERGED_DELETED_BRANCHES variable to the pipeline. I could do mapfile -t MERGED_DELETED_BRANCHES <<< $(git branch ...) but it doesn't feel much better than what's there already.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. Maybe the GNU version behaves differently. Still fine to merge :)

@matt-froggatt matt-froggatt merged commit 2f4b15c into master Apr 10, 2026
@matt-froggatt matt-froggatt deleted the ACTIN-3460 branch April 10, 2026 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants