jesseduffield/lazygit · warning
You cannot merge a branch into itself
Error message
You cannot merge a branch into itself
What it means
Returned by MergeRefIntoCheckedOutBranch when the requested merge source refName equals the checked-out branch name (Branches[0]). Merging a branch into itself is a git no-op-at-best and confusing-at-worst, so lazygit rejects it immediately after the detached-head check and before building the fast-forward/regular merge menu.
Source
Thrown at pkg/gui/controllers/helpers/merge_and_rebase_helper.go:524
self.c.Tr.RebasingTitle),
map[string]string{
"checkedOutBranch": checkedOutBranchName,
},
)
return self.c.Menu(types.CreateMenuOptions{
Title: title,
Items: menuItems,
})
}
func (self *MergeAndRebaseHelper) MergeRefIntoCheckedOutBranch(refName string) error {
if self.c.Git().Branch.IsHeadDetached() {
return errors.New("Cannot merge branch in detached head state. You might have checked out a commit directly or a remote branch, in which case you should checkout the local branch you want to be on")
}
checkedOutBranchName := self.c.Model().Branches[0].Name
if checkedOutBranchName == refName {
return errors.New(self.c.Tr.CantMergeBranchIntoItself)
}
wantFastForward, wantNonFastForward := self.fastForwardMergeUserPreference()
canFastForward := self.c.Git().Branch.CanDoFastForwardMerge(refName)
var firstRegularMergeItem *types.MenuItem
var secondRegularMergeItem *types.MenuItem
var fastForwardMergeItem *types.MenuItem
if !wantNonFastForward && (wantFastForward || canFastForward) {
firstRegularMergeItem = &types.MenuItem{
Label: self.c.Tr.RegularMergeFastForward,
OnPress: self.RegularMerge(refName, git_commands.MERGE_VARIANT_REGULAR),
Keys: menuKey('m'),
Tooltip: utils.ResolvePlaceholderString(
self.c.Tr.RegularMergeFastForwardTooltip,
map[string]string{
"checkedOutBranch": checkedOutBranchName,View on GitHub (pinned to c477a2959b)
Solutions
- Move the selection to a different branch before merging.
- To update the current branch from its remote, use the pull keybinding (p) instead of merge.
Defensive patterns
Strategy: validation
Validate before calling
// before merging:
if checkedOutBranchName == refName {
// no-op guard: deselect or use pull for upstream updates
} Prevention
- Move the cursor off the current branch before pressing merge
- Use pull (p) to update the current branch from its upstream
When it happens
Trigger: Highlighting the current branch in the Branches panel (it is the top entry, so it is the default selection) and pressing the merge keybinding (M).
Common situations: Muscle-memory pressing M without moving the cursor off the current branch; assuming 'merge' means 'pull/update this branch from its upstream' — for that, use the pull command instead.
Related errors
- Cannot merge branch in detached head state. You might have c
- Some of the selected branches are checked out by other workt
- You are currently neither rebasing nor merging
- You cannot remove the main worktree!
- Git version must be at least %s. Please upgrade your git ver
AI-assisted analysis of jesseduffield/lazygit@c477a2959b (2026-08-15).
Data as JSON: /api/errors/fb6c968025a56158.
Report an issue: GitHub.