{"record":{"id":"cb4c15ef78a2a4fb","repo":"jesseduffield/lazygit","slug":"updates-were-rejected-please-fetch-and-examine-th","errorCode":null,"errorMessage":"Updates were rejected. Please fetch and examine the remote changes before pushing again.","messagePattern":"Updates were rejected\\. Please fetch and examine the remote changes before pushing again\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gui/controllers/sync_controller.go","lineNumber":211,"sourceCode":"}\n\nfunc (self *SyncController) pushAux(currentBranch *models.Branch, opts pushOpts) error {\n\treturn self.c.WithInlineStatus(currentBranch, types.ItemOperationPushing, context.LOCAL_BRANCHES_CONTEXT_KEY, func(task gocui.Task) error {\n\t\tself.c.LogAction(self.c.Tr.Actions.Push)\n\t\terr := self.c.Git().Sync.Push(\n\t\t\ttask,\n\t\t\tgit_commands.PushOpts{\n\t\t\t\tForce:          opts.force,\n\t\t\t\tForceWithLease: opts.forceWithLease,\n\t\t\t\tCurrentBranch:  currentBranch.Name,\n\t\t\t\tUpstreamRemote: opts.upstreamRemote,\n\t\t\t\tUpstreamBranch: opts.upstreamBranch,\n\t\t\t\tSetUpstream:    opts.setUpstream,\n\t\t\t})\n\t\tif err != nil {\n\t\t\tif !opts.force && !opts.forceWithLease && strings.Contains(err.Error(), \"Updates were rejected\") {\n\t\t\t\tif opts.remoteBranchStoredLocally {\n\t\t\t\t\treturn errors.New(self.c.Tr.UpdatesRejected)\n\t\t\t\t}\n\n\t\t\t\tforcePushDisabled := self.c.UserConfig().Git.DisableForcePushing\n\t\t\t\tif forcePushDisabled {\n\t\t\t\t\treturn errors.New(self.c.Tr.UpdatesRejectedAndForcePushDisabled)\n\t\t\t\t}\n\t\t\t\tself.c.Confirm(types.ConfirmOpts{\n\t\t\t\t\tTitle:  self.c.Tr.ForcePush,\n\t\t\t\t\tPrompt: self.forcePushPrompt(),\n\t\t\t\t\tHandleConfirm: func() error {\n\t\t\t\t\t\tnewOpts := opts\n\t\t\t\t\t\tnewOpts.force = true\n\n\t\t\t\t\t\treturn self.pushAux(currentBranch, newOpts)\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t\treturn nil\n\t\t\t}","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/jesseduffield/lazygit/blob/c477a2959b229fbf3284be0d4d2904ab61ec3c94/pkg/gui/controllers/sync_controller.go#L193-L229","documentation":"Returned by SyncController.pushAux when a non-force push fails with git's 'Updates were rejected' message and opts.remoteBranchStoredLocally is true. Because the remote branch already exists locally as a tracking ref, lazygit knows the divergence is genuine and tells the user to fetch and examine remote changes instead of immediately offering to force push over them.","triggerScenarios":"Plain 'p' (push) with !opts.force && !opts.forceWithLease while the local branch is behind/diverged from its upstream and git rejects with 'Updates were rejected'; the upstream remote-tracking branch is present in the local refs.","commonSituations":"Another machine or teammate pushed to the same branch; a rebase/rewrite happened elsewhere; user pushed from a second worktree.","solutions":["Fetch (f) and inspect incoming commits, then merge or rebase onto the remote branch and push again.","If the local history is authoritative and should replace the remote, force-push with lease after confirmation (force pushing must be enabled in config).","Check that you are pushing the intended branch/upstream if divergence is unexpected."],"exampleFix":"# before\n$ git push   # rejected\n\n# after\n$ git fetch && git log HEAD..@{u}   # examine remote changes\n$ git pull --rebase && git push","handlingStrategy":"fallback","validationCode":"local, _ := self.c.Model().Branches.Get(...)\nif local != nil && local.IsBehindRemote() /* or compare hashes */ {\n    // fetch/rebase before pushing\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Fetch before pushing when working on shared branches.","Compare local vs upstream hashes (or use PushingStatus) and offer rebase/merge before push.","Prefer force-with-lease over force when history must be replaced."],"tags":["git","push","divergence","non-fast-forward"],"backgroundTag":null,"analyzedSha":"c477a2959b229fbf3284be0d4d2904ab61ec3c94","analyzedAt":"2026-08-15T08:34:32.451Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}