Skip to content

claude-code template: recommend GitHub's "Automatically delete head branches" setting in the README #202

Open

Description

@gatezh

Problem

New GitHub repos keep a PR's branch after the PR is merged. Projects built from the claude-code template make a lot of short-lived branches. Claude sessions open one branch, and often one worktree, per change. The merged branches pile up on GitHub until someone cleans them up by hand.

In one downstream project, 21 of the 22 remote branches were already merged when someone looked. Every one of them had to be checked against master before it was safe to delete, because git push --delete deletes whatever it's given, merged or not.

Proposal

Recommend GitHub's "Automatically delete head branches" setting in the README's project setup steps. It's a per-repo setting, so it can't go in .devcontainer/:

gh api -X PATCH repos/<owner>/<repo> -F delete_branch_on_merge=true

Or go to Settings → General → Pull Requests → Automatically delete head branches. It needs admin rights on the repo.

Notes for the README:

  • It only affects PRs merged after the setting is turned on. Branches that are already merged still have to be deleted by hand.
  • Only the GitHub branch is deleted. Local branches and worktrees stay until git fetch --prune plus git branch -d, or git worktree remove.
  • Branch protection rules and rulesets can stop a branch from being deleted (GitHub docs).

This repo has the setting off too (delete_branch_on_merge: false), so it could be turned on here as well.

Acceptance

  • The README's setup section recommends the setting and shows the gh api command.
  • The setting is on for gatezh/devcontainers.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions