jesseduffield/lazygit · error
Updates were rejected. Please fetch and examine the remote c
Error message
Updates were rejected. Please fetch and examine the remote changes before pushing again.
What it means
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.
Source
Thrown at pkg/gui/controllers/sync_controller.go:211
}
func (self *SyncController) pushAux(currentBranch *models.Branch, opts pushOpts) error {
return self.c.WithInlineStatus(currentBranch, types.ItemOperationPushing, context.LOCAL_BRANCHES_CONTEXT_KEY, func(task gocui.Task) error {
self.c.LogAction(self.c.Tr.Actions.Push)
err := self.c.Git().Sync.Push(
task,
git_commands.PushOpts{
Force: opts.force,
ForceWithLease: opts.forceWithLease,
CurrentBranch: currentBranch.Name,
UpstreamRemote: opts.upstreamRemote,
UpstreamBranch: opts.upstreamBranch,
SetUpstream: opts.setUpstream,
})
if err != nil {
if !opts.force && !opts.forceWithLease && strings.Contains(err.Error(), "Updates were rejected") {
if opts.remoteBranchStoredLocally {
return errors.New(self.c.Tr.UpdatesRejected)
}
forcePushDisabled := self.c.UserConfig().Git.DisableForcePushing
if forcePushDisabled {
return errors.New(self.c.Tr.UpdatesRejectedAndForcePushDisabled)
}
self.c.Confirm(types.ConfirmOpts{
Title: self.c.Tr.ForcePush,
Prompt: self.forcePushPrompt(),
HandleConfirm: func() error {
newOpts := opts
newOpts.force = true
return self.pushAux(currentBranch, newOpts)
},
})
return nil
}View on GitHub (pinned to c477a2959b)
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.
Example fix
# before
$ git push # rejected
# after
$ git fetch && git log HEAD..@{u} # examine remote changes
$ git pull --rebase && git push Defensive patterns
Strategy: fallback
Validate before calling
local, _ := self.c.Model().Branches.Get(...)
if local != nil && local.IsBehindRemote() /* or compare hashes */ {
// fetch/rebase before pushing
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Another machine or teammate pushed to the same branch; a rebase/rewrite happened elsewhere; user pushed from a second worktree.
Related errors
- Must specify a remote if specifying a branch
- Updates rejected and you have disabled force pushing
- Your branch has diverged from the remote branch and you've d
- Git version must be at least %s. Please upgrade your git ver
- Lazygit does not support bare repos.
AI-assisted analysis of jesseduffield/lazygit@c477a2959b (2026-08-15).
Data as JSON: /api/errors/cb4c15ef78a2a4fb.
Report an issue: GitHub.