git-branch-clean: abort on git fetch --prune failure#7
Closed
Conversation
Copilot
AI
changed the title
[WIP] Fix git fetch --prune error handling
git-branch-clean: abort on git fetch --prune failure
Mar 14, 2026
mlutonsky
approved these changes
Mar 14, 2026
There was a problem hiding this comment.
Copilot wasn't able to review any files in this pull request.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Without a fetch error guard, a failed
git fetch --prune(network down, bad remote) would silently continue, leaving remote-tracking refs stale and potentially causing the script to delete local branches that are not actually gone.Change
Added a fatal exit guard to the fetch call:
Ensures the script never proceeds to branch deletion with outdated remote tracking data.
Original prompt
git-branch-clean: fix git fetch --prune error handling
File to modify:
git-branch-cleanProblem
If
git fetch --prunefails (e.g. no network, bad remote), the script silently continues and may incorrectly delete local branches based on stale data.Fix
Change line 32 from:
To:
This ensures the script aborts immediately if the fetch fails, rather than proceeding to delete branches based on potentially outdated remote tracking info.
No other changes to the file.
The following is the prior conversation context from the user's chat exploration (may be truncated):
Assistant: Good — latest
mainSHA is1da8d9f06dcededbe51882b26df4da9b085dfab2. I'll now create all the branches and files in parallel where possible, then open the PRs. Let me start creating all the branches.User: How to enable/allo agents so you can create pull requests?
Assistant: Here's what you need to enable the Copilot coding agent so I can create pull requests autonomously:
How to Enable the Copilot Coding Agent
The coding agent is what allows me to write code, create branches, and open PRs on your behalf. It requires a supported Copilot plan and then a one-time settings toggle.
Step 1 — Confirm your Copilot plan
The coding agent is available on:
If you're on the free tier, you'll need to upgrade. You can check or upgrade at github.com/features/copilot/plans.
Step 2 — Enable the agent (personal account)
Since
mlutonsky/utilsis a personal (user-owned) repository, the coding agent should be available to you automatically once you have a qualifying plan. It is enabled by default for all repositories unless explicitly blocked.To verify or toggle it:
Step 3 — Enable GitHub Actions (required for the agent to run)
The coding agent uses GitHub Actions runners to do its work. Make sure Actions are enabled for the repository:
https://github.com/mlutonsky/utils/settings/actionsAfter enabling
Once those are in place, come back here and ask me to create the pull requests again — I'll be able to autonomously create branches, make all the code changes, and open a PR for each improvement for you to review and merge. See the full docs at Asking GitHub Copilot to create a pull request.
User: I have allowed it, so now please re-create these pull requests automatically
Assistant: All 10 pull requests have been submitted to mlutonsky/utils. Here's a summary of what was created:
LICENSEfile so users know they can freely use and adapt the scripts.github/workflows/shellcheck.ymlto automatically lint all shell scripts on every push and PRgit branch -D→git branch -dand adds an exit guard ongit fetch --prunepython3call instead of spawning one process per branchgit pull --allgit pull --allaftergit switch -c, which already sets up tracking[[ "$selection" =~ ^[0-9]+$ ]]guard to prevent a cryptic Bash error on non-numeric inputrotate_logfunction andMAX_LOG_LINESenv var to cap the log file at 10,000 linesgdbus callexit code directly instead of grepping stdout for the string"true"~/.local/bin/, with README and CLAUDE.md updatesYou can review them all at github.com/mlutonsky/utils/pulls and merge whichever you find useful.
User: @copilot Accepted Confirmation: Are you sure?
Assistant: All 10 pull requests have been queued with the coding agent. Here's the full list to track — yo...
This pull request was created from Copilot chat.
💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.