{"record":{"id":"fb6c968025a56158","repo":"jesseduffield/lazygit","slug":"you-cannot-merge-a-branch-into-itself","errorCode":null,"errorMessage":"You cannot merge a branch into itself","messagePattern":"You cannot merge a branch into itself","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/gui/controllers/helpers/merge_and_rebase_helper.go","lineNumber":524,"sourceCode":"\t\t\tself.c.Tr.RebasingTitle),\n\t\tmap[string]string{\n\t\t\t\"checkedOutBranch\": checkedOutBranchName,\n\t\t},\n\t)\n\n\treturn self.c.Menu(types.CreateMenuOptions{\n\t\tTitle: title,\n\t\tItems: menuItems,\n\t})\n}\n\nfunc (self *MergeAndRebaseHelper) MergeRefIntoCheckedOutBranch(refName string) error {\n\tif self.c.Git().Branch.IsHeadDetached() {\n\t\treturn 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\")\n\t}\n\tcheckedOutBranchName := self.c.Model().Branches[0].Name\n\tif checkedOutBranchName == refName {\n\t\treturn errors.New(self.c.Tr.CantMergeBranchIntoItself)\n\t}\n\n\twantFastForward, wantNonFastForward := self.fastForwardMergeUserPreference()\n\tcanFastForward := self.c.Git().Branch.CanDoFastForwardMerge(refName)\n\n\tvar firstRegularMergeItem *types.MenuItem\n\tvar secondRegularMergeItem *types.MenuItem\n\tvar fastForwardMergeItem *types.MenuItem\n\n\tif !wantNonFastForward && (wantFastForward || canFastForward) {\n\t\tfirstRegularMergeItem = &types.MenuItem{\n\t\t\tLabel:   self.c.Tr.RegularMergeFastForward,\n\t\t\tOnPress: self.RegularMerge(refName, git_commands.MERGE_VARIANT_REGULAR),\n\t\t\tKeys:    menuKey('m'),\n\t\t\tTooltip: utils.ResolvePlaceholderString(\n\t\t\t\tself.c.Tr.RegularMergeFastForwardTooltip,\n\t\t\t\tmap[string]string{\n\t\t\t\t\t\"checkedOutBranch\": checkedOutBranchName,","sourceCodeStart":506,"sourceCodeEnd":542,"githubUrl":"https://github.com/jesseduffield/lazygit/blob/c477a2959b229fbf3284be0d4d2904ab61ec3c94/pkg/gui/controllers/helpers/merge_and_rebase_helper.go#L506-L542","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// before merging:\nif checkedOutBranchName == refName {\n    // no-op guard: deselect or use pull for upstream updates\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Move the cursor off the current branch before pressing merge","Use pull (p) to update the current branch from its upstream"],"tags":["git","merge","self-merge","guard"],"backgroundTag":null,"analyzedSha":"c477a2959b229fbf3284be0d4d2904ab61ec3c94","analyzedAt":"2026-08-15T08:34:32.451Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}