Skip to content

feat: add branch sorting option#88

Open
kurtextrem wants to merge 3 commits intopol-rivero:mainfrom
kurtextrem:feature/branch-sorting
Open

feat: add branch sorting option#88
kurtextrem wants to merge 3 commits intopol-rivero:mainfrom
kurtextrem:feature/branch-sorting

Conversation

@kurtextrem
Copy link

@kurtextrem kurtextrem commented Mar 16, 2026

Description

Hi! Thanks for maintaining this. I love it.

What I also love is the "Recent branches" list. Especially with AI, I try multiple things at the same time. So just showing 5 is not enough. I thought about adding a setting that changes the amount of branches that are displayed in "Recent branches", but I figured: It's much more useful to either sort by recently added (what "Recent branches" currently does), or new, "Recently changed" (based on commits).

Screenshots

image image

Release notes

Notes:

  • Settings: Added an option in "Appearance" that allows to configure branch sorting (by alphabet - default, by recently added, or recently changed (last commit))

Copilot AI review requested due to automatic review settings March 16, 2026 08:33
Copy link

Copilot AI left a comment

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 user-configurable branch sorting preference that affects branch-selection views (e.g., branch dropdown/history compare), persisted in app state and exposed in Preferences.

Changes:

  • Introduces a BranchSortOrder preference stored in AppStore/localStorage and wired through UI props.
  • Updates branch grouping/sorting logic to support Alphabet, Recently Added (reflog order), and Recently Changed (by last commit date).
  • Adjusts recent-branch loading limits in GitStore based on the selected sort mode, and adds/updates unit tests.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
app/test/unit/group-branches-test.ts Adds coverage for new sort modes and recent-branch capping behavior.
app/src/ui/toolbar/branch-dropdown.tsx Threads branchSortOrder prop into branch dropdown rendering.
app/src/ui/repository.tsx Passes branchSortOrder down into repository view children.
app/src/ui/preferences/preferences.tsx Adds branchSortOrder to preferences state and persists via dispatcher.
app/src/ui/preferences/appearance.tsx Adds Appearance UI for selecting branch sort order.
app/src/ui/history/compare.tsx Passes branchSortOrder into compare sidebar branch list.
app/src/ui/dispatcher/dispatcher.ts Adds dispatcher API for updating branch sort order.
app/src/ui/branches/group-branches.ts Implements new grouping/sorting behavior based on sort order.
app/src/ui/branches/branches-container.tsx Threads branchSortOrder into BranchList.
app/src/ui/branches/branch-list.tsx Updates group header labeling based on sort order.
app/src/ui/app.tsx Passes app state branchSortOrder into relevant UI surfaces.
app/src/models/branch-sort-order.ts Adds the sort order model/default.
app/src/lib/stores/git-store.ts Adds sort-dependent recent-branch limits and extends loadBranches.
app/src/lib/stores/app-store.ts Persists the setting, reloads branches on change, and wires into initial load.
app/src/lib/app-state.ts Extends global app state with branchSortOrder.

You can also share your feedback on Copilot code review. Take the survey.

@pol-rivero
Copy link
Owner

Thanks for your PR! I agree that it would be nice to be able to sort branches by "Recently changed" instead of alphabetically.

Everything seems to be working fine, with the exception that local branches are no longer shown at the top.
I think they should remain grouped at the top (ordered by changed date), followed by all remote branches (ordered by date), because local branches are much more important than remote branches.

Old:

image

New:

image

Comment on lines +7536 to +7546
bitbucket: `${htmlURL}/pull-requests/new?${param(
'source',
encodedCompareBranch
)}&${param('dest', encodedBaseBranch)}`,
github: `${htmlURL}/pull/new/${
encodedBaseBranch ? encodedBaseBranch + '...' : ''
}${encodedCompareBranch}`,
gitlab: `${htmlURL}/merge_requests/new?${param(
'merge_request[source_branch]',
encodedCompareBranch
)}&${param('merge_request[target_branch]', encodedBaseBranch)}`,
Copy link
Owner

@pol-rivero pol-rivero Mar 16, 2026

Choose a reason for hiding this comment

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

Why did you change the formatting in these lines? There doesn't seem to be any content changes.

Copy link
Author

Choose a reason for hiding this comment

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

I've run prettier locally and it has changed the lines. GitHub Copilot then commented on the formatting, so not really sure what happened. I can revert.

Copy link
Owner

@pol-rivero pol-rivero Mar 16, 2026

Choose a reason for hiding this comment

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

That's strange, PR_URLS has a // prettier-ignore comment, so it should be ignored...

I added that exception because these constructed URLs become practically unreadable when formatted.

* The max number of recent branches to include for non-alphabetic
* sorts where full "recent" list ordering is required.
*/
const RecentOptionsBranchLimit = 2500
Copy link
Owner

@pol-rivero pol-rivero Mar 16, 2026

Choose a reason for hiding this comment

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

2500 seems like an arbitrary limit, and some repos can have way more branches. There should be no limit.
I think that the current approach of just extending the "Recent branches" section is flawed. It would be much better to just hide the "Recent branches" section and change the sorting of the "Other branches" section. This might give you the grouping of local branches at the top (see my first comment) "for free".

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.

3 participants