cli / cli/cli

CLI command to clean up after a merged PR

Open
#380 24 comments 82 reactions 0 assignees View on GitHub
core enhancement gh-pr pitch
Dominant language
Go
Stars
46.3k
Forks
9k
Avg merge
2d 6h
Merged PRs (30d)
97

Description

### Describe the feature or problem you’d like to solve

After a PR of mine has been merged I currently have to

* click the button in the GUI to delete the branch (typically from a fork)
* navigate to my local clone
* run:

```bash
git checkout master # if not already on base branch
git pull
git branch -d local-branch
```

This is a bunch of manual steps which I need to repeat several times on a good day.

### Proposed solution

Navigate to the local clone and

```bash
gh pr cleanup 123
```

ought to take care of deleting the various branches for me. Or even

```bash
gh pr cleanup --all
```

to clean up branches from any of my PRs which were merged since I last ran this.

Ideally this would fast-forward my local base branch reference without actually needing to check it out, in case I currently had checked out some other (unmerged) branch or had local modifications.

For bonus points, if some rude maintainer used squash or rebase, verify that the base branch really contains all the changes in my local branch before deleting it. Otherwise I need to check this manually if I am being careful. (Genuine merges behave better: if for example I forgot to push some last-minute commits, `git branch -d` will warn me that the branch is not actually merged. This warning is useless for squashed or rebased PRs because it is _always_ printed.)

### Additional context

N/A

Contributor guide

Open the contributing guide

Research direction

Start from the proposed `gh pr cleanup 123` and `gh pr cleanup --all` entry points, then review the Git operations shown in the issue: updating the base branch, deleting local and fork branches, and checking squash or rebased changes. Done means merged PR branches can be cleaned up without checking out the base branch or deleting unmerged work.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, github, go
Domain
cli, developer-experience
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.