From c0d9640c0b37540bb15bb25d53e62ad0b4c8911e Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 11 Apr 2026 17:04:14 +0200 Subject: [PATCH] Hide closed pull requests on main branches The assumption is that if a pull request exists on a main branch, it was usually created by mistake and then closed, and showing it serves no purpose and is only distracting. We keep showing open pull requests for main branches though, because this allows you to notice that there is one that you probably want to close. This only affects the display (in the branches list and in the main view); opening the PR in the browser using shift-G is still possible, as is copying its URL to the clipboard. --- pkg/gui/controllers/branches_controller.go | 4 +++- pkg/gui/presentation/branches.go | 12 +++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go index 1c3d9e350..3bda52453 100644 --- a/pkg/gui/controllers/branches_controller.go +++ b/pkg/gui/controllers/branches_controller.go @@ -11,6 +11,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers" + "github.com/jesseduffield/lazygit/pkg/gui/presentation" "github.com/jesseduffield/lazygit/pkg/gui/presentation/icons" "github.com/jesseduffield/lazygit/pkg/gui/style" "github.com/jesseduffield/lazygit/pkg/gui/types" @@ -205,7 +206,8 @@ func (self *BranchesController) GetOnRenderToMain() func() { ptyTask := types.NewRunPtyTask(cmdObj.GetCmd()) task = ptyTask - if pr, ok := self.c.Model().PullRequestsMap[branch.Name]; ok { + pr, ok := self.c.Model().PullRequestsMap[branch.Name] + if ok && presentation.ShouldShowPrForBranch(pr, branch.Name, self.c.UserConfig()) { icon := lo.Ternary(icons.IsIconEnabled(), icons.IconForRemoteUrl(pr.Url)+" ", "") ptyTask.Prefix = style.PrintHyperlink(fmt.Sprintf("%s%s %s %s\n", icon, diff --git a/pkg/gui/presentation/branches.go b/pkg/gui/presentation/branches.go index f406547bc..f7c624682 100644 --- a/pkg/gui/presentation/branches.go +++ b/pkg/gui/presentation/branches.go @@ -141,7 +141,7 @@ func getBranchDisplayStrings( var coloredPrIcon string pr, hasPr := prs[b.Name] - if hasPr { + if hasPr && ShouldShowPrForBranch(pr, b.Name, userConfig) { var prIcon string if icons.IsIconEnabled() { prIcon = icons.IconForRemoteUrl(pr.Url) @@ -285,3 +285,13 @@ func prColor(state string) style.TextStyle { return style.FgDefault } } + +func ShouldShowPrForBranch(pr *models.GithubPullRequest, branchName string, userConfig *config.UserConfig) bool { + if !lo.Contains(userConfig.Git.MainBranches, branchName) { + return true + } + + // For main branches we only want to show the PR if it's open (or draft), on the assumption that a + // closed PR for a main branch is always a mistake. + return pr.State != "CLOSED" && pr.State != "MERGED" +}