From 9183269ee8fb8361499fce1f84064676be33883a Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Wed, 23 Sep 2026 14:43:51 +0200 Subject: [PATCH] Write a reflog message when moving branch refs Branches that lazygit forwards to their upstream move by a direct ref write, so no git command turns up in their reflog to explain it. Until now the entry had no message either, leaving `git reflog ` with nothing but a blank line about it. Name lazygit and what it did, so that a branch which moved on its own can be traced. Co-Authored-By: Claude Opus 5 (1M context) --- pkg/commands/git_commands/branch.go | 6 +++++- pkg/gui/controllers/helpers/branches_helper.go | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/commands/git_commands/branch.go b/pkg/commands/git_commands/branch.go index 6d060613a..19dba12fe 100644 --- a/pkg/commands/git_commands/branch.go +++ b/pkg/commands/git_commands/branch.go @@ -440,9 +440,13 @@ func (self *BranchCommands) previousUpstreamValues(upstreamRef string) []string return values } -func (self *BranchCommands) UpdateBranchRefs(updateCommands string) error { +// Moves branches by writing refs directly. The reflog message is what +// `git reflog ` shows for the update; it is the only hint about who +// moved the branch, as no git command shows up in the reflog for this. +func (self *BranchCommands) UpdateBranchRefs(updateCommands string, reflogMessage string) error { cmdArgs := NewGitCmd("update-ref"). Arg("--stdin"). + Arg("-m", reflogMessage). ToArgv() return self.cmd.New(cmdArgs).SetStdin(updateCommands).Run() diff --git a/pkg/gui/controllers/helpers/branches_helper.go b/pkg/gui/controllers/helpers/branches_helper.go index effbf6a42..29c27f93e 100644 --- a/pkg/gui/controllers/helpers/branches_helper.go +++ b/pkg/gui/controllers/helpers/branches_helper.go @@ -577,7 +577,7 @@ func (self *BranchesHelper) forwardBranches(toForward []*branchToForward) error if updateCommands != "" { self.c.LogCommand(strings.TrimRight(updateCommands, "\n"), false) - if err := self.c.Git().Branch.UpdateBranchRefs(updateCommands); err != nil { + if err := self.c.Git().Branch.UpdateBranchRefs(updateCommands, "lazygit: update to upstream branch"); err != nil { return err } } @@ -647,7 +647,7 @@ func (self *BranchesHelper) AutoForwardBranches(background bool) error { self.c.LogAction(self.c.Tr.Actions.AutoForwardBranches) self.c.LogCommand(strings.TrimRight(updateCommands, "\n"), false) - err := self.c.Git().Branch.UpdateBranchRefs(updateCommands) + err := self.c.Git().Branch.UpdateBranchRefs(updateCommands, "lazygit: fast-forward to upstream branch") self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES}, Background: background})