Skip to content

delete-branch - New feature - #9974

Merged
fregante merged 19 commits into
refined-github:mainfrom
Sebastien-Ahkrin:feat/quick-branch-deletion
Aug 23, 2026
Merged

fregante merged 19 commits into
refined-github:mainfrom
Sebastien-Ahkrin:feat/quick-branch-deletion

Conversation

@Sebastien-Ahkrin

@Sebastien-Ahkrin Sebastien-Ahkrin commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #8617

I checked if someone already implemented this one, I saw this PR. I used it a little for the rendering of my button. Hope this is good.

Multiple questions are still here :

  1. Do we have to cancel the suppression (mostly disabled the button) if the current branch has any open PR
  2. Should we add a confirmation before removing the branch

Number 2 is not really required, because we can revert the change on the next page ...

Warning

The testing url looks to not be working CF my screen. Then, I choose to use this one instead. BUT, this will work only for maintainer. Other user's who's gonna test the PR, you will have to create a new branch on your own fork or project.

Screen of the page CleanShot 2026-08-12 at 17 12 38

Test URLs

  1. for maintainer (DO NOT CLICK ON THE BUTTON) https://github.com/refined-github/refined-github/tree/sandbox/keep-branch
  2. Else, create a new branch on your own fork or project

Screenshot / GIF

GIF are from Chrome, other screenshots are from Firefox / Safari

Workflow from Chrome

workflows-quick-branches-deletion

Screenshot from Firefox

quick-deletion-firefox

Screenshot from Safari

pr-quick-branches-safari-deletion

Screenshot for README (with green arrow)

pr-quick-branches-deletion

@Sebastien-Ahkrin
Sebastien-Ahkrin marked this pull request as ready for review August 12, 2026 15:21
@Sebastien-Ahkrin
Sebastien-Ahkrin marked this pull request as draft August 12, 2026 15:25
@Sebastien-Ahkrin
Sebastien-Ahkrin marked this pull request as ready for review August 12, 2026 15:27
@fregante

Copy link
Copy Markdown
Member

Do we have to cancel the suppression (mostly disabled the button) if the current branch has any open PR

Good questions. GitHub shows the button and then asks for confirmation, with extensive information.

We can't show the same popup style so I'm leaning towards not showing the button at all. I don’t think anyone would really want to close a PR this way.

So no button.

Should we add a confirmation before removing the branch

So GitHub does it in the first case, but not when there's nothing linked to it. However GitHub also has a quick way to restore the deletion a few clicks away, whereas our redirect is more confusing.

So yeah let's just use confirm() here.

@fregante fregante left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

By the way you only need screenshots from one browser. We rarely have browser-specific bugs

Comment thread build/__snapshots__/features-meta.json Resolved
Comment thread source/features/delete-branch.tsx Resolved
@Sebastien-Ahkrin
Sebastien-Ahkrin marked this pull request as draft August 12, 2026 16:53
@Sebastien-Ahkrin

Sebastien-Ahkrin commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor Author

On branch with open PR :

  • no button displayed
CleanShot 2026-08-12 at 20 05 58

On branch without any PR open

  • button to delete displayed
CleanShot 2026-08-12 at 20 06 42

A confirm dialog is open if you click on the button. Then, the branch is now deleted.

CleanShot 2026-08-12 at 20 10 54

@Sebastien-Ahkrin
Sebastien-Ahkrin marked this pull request as ready for review August 12, 2026 18:12
@Sebastien-Ahkrin Sebastien-Ahkrin changed the title quick-branch-deletion - Add button to easily delete branche delete-branch - Add button to easily delete branche Aug 12, 2026
@Sebastien-Ahkrin
Sebastien-Ahkrin marked this pull request as draft August 12, 2026 18:54
@Sebastien-Ahkrin

Sebastien-Ahkrin commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Test of each pages / modals / layout

On main branch (should be disabled, we cannot remove main with quick delete)

CleanShot 2026-08-12 at 20 53 21

On new branch inside a fork but not linked to any PR

CleanShot 2026-08-12 at 20 56 50

On new branch outside a fork

CleanShot 2026-08-12 at 20 56 08

When clicking on delete button

CleanShot 2026-08-12 at 20 58 15

When comiting the delete

CleanShot 2026-08-12 at 20 58 53

On branch, but whithout push permission

CleanShot 2026-08-12 at 20 59 59

@fregante Did I miss something ?

Plus, for my own sanity I checked on Firefox, Chrome, and Safari. The feature looks the same on every brother !

Safari
CleanShot 2026-08-12 at 21 05 27

Firefox
CleanShot 2026-08-12 at 21 06 06

@Sebastien-Ahkrin
Sebastien-Ahkrin marked this pull request as ready for review August 12, 2026 19:08
Comment thread source/refined-github.ts Resolved
Comment thread source/features/delete-branch.tsx Outdated
Comment on lines +33 to +37
const pullRequests = await api.v3(
`/repos/${targetRepository}/pulls?head=${owner}:${branchName}&state=open`,
);

return pullRequests.length === 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Non-fork repos already show the current PR on the same line, we don't need an API request.

As for fork repos... not sure it's worth the effort... however it seems relatively simple

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.

Ok !

With the new code, if I am on a non-fork repository, and I am on a branch that has PR.
I have this :

CleanShot 2026-08-12 at 22 07 31

Selector are : &&optional if I have the icon with 1 or something (check on the url) then, I am on a branch that have PR, so we are not able to delete the branch.

If i don't have the icon then, we can delete the branch

CleanShot 2026-08-12 at 22 09 16

All of that in non-fork without querying api.

If I am on a fork + on a branch that is a PR we cannot delete the branch

CleanShot 2026-08-12 at 22 10 14

And, if I am on a fork, with a branch that is not a pr, then, I can delete the branch

CleanShot 2026-08-12 at 22 11 21

Comment thread source/features/delete-branch.tsx Resolved
Comment thread source/features/delete-branch.tsx Resolved
Comment thread source/features/delete-branch.tsx Resolved
@fregante

Copy link
Copy Markdown
Member
Screenshot

Comment on lines +38 to +45
function add(contributeContainer: HTMLElement): void {
if (elementExists([
// No button if there are open PRs
'a[class*="PullRequestLink-module"]',
// No button if the branch is linked to upstream repo (generally the main branch)
'.octicon-sync',
], contributeContainer)) {
return;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No API calls required, all the info we need is on the page

<button
type="button"
className="btn btn-danger rgh-delete-branch"
ref={withTooltipRef('Delete branch')}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The button label was too long and had the wrong text size. GitHub's own trash button is unlabelled

export function getForkedRepo(): string | undefined {
return $optional('meta[name="octolytics-dimension-repository_parent_nwo"]')?.content;
export function getForkedRepo(): `${string}/${string}` | undefined {
return $optional('meta[name="octolytics-dimension-repository_parent_nwo"]')?.content as

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This already existed. It turns out we don't need it after all, the information already appears on forks. See open PR link/icon on https://github.com/refined-github/sandbox/tree/sdfsdfds

Image

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a new Refined GitHub feature that surfaces a “Delete branch” button on branch /tree/* pages, enabling maintainers to delete the currently viewed branch without navigating back to the branches list.

Changes:

  • Registered a new delete-branch feature in the extension entrypoint.
  • Implemented the UI + API call to delete the current branch and then redirect.
  • Updated README and generated feature metadata snapshots to include the new feature.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
source/refined-github.ts Registers the new delete-branch feature for loading.
source/github-helpers/index.ts Tightens the return type of getForkedRepo() to a owner/repo template string.
source/features/delete-branch.tsx New feature: injects a delete button and performs the delete request.
readme.md Documents the new feature in the feature list.
build/snapshots/imported-features.json Adds delete-branch to the imported features snapshot.
build/snapshots/features-meta.json Adds metadata entry for delete-branch.
Suppressed comments (1)

source/features/delete-branch.tsx:71

  • The feature is gated behind pageDetect.isRepoRoot, but the branch info bar only exists on /tree/* pages, so this feature won't run where it's needed. Limit it to repo tree pages and exclude tags/commit permalinks (otherwise the button can appear on tag/SHA views and the delete call will fail).
	asLongAs: [
		pageDetect.isRepoRoot,
	],
	requiresToken: true,
	init,

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.


import features from '../feature-manager.js';
import observe from '../helpers/selector-observer.js';
import {buildRepoUrl} from '../github-helpers/index.js';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There's no bar on permalinks

Comment thread source/features/delete-branch.tsx Resolved
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
@fregante fregante changed the title delete-branch - Add button to easily delete branche delete-branch - New feature Aug 23, 2026
@fregante
fregante merged commit 6631373 into refined-github:main Aug 23, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Add button to delete current branch on /tree/

3 participants