jesseduffield/lazygit · error

{{errMsg}}

Error message

{{errMsg}}

What it means

Returned by ReposHelper.switchToLocation when os.Chdir to the target repo path fails with fs.ErrNotExist: the recorded directory (recent repo, worktree path, or command-line arg) no longer exists on disk. The message itself is caller-supplied — each switchTo caller passes context (e.g. 'repo no longer exists' vs 'worktree no longer exists') — and non-NotExist chdir errors are returned raw. Env vars for git-dir/work-tree are restored before failing so the current session stays consistent.

Source

Thrown at pkg/gui/controllers/helpers/repos_helper.go:231

// work tree (a dotfile repo opened with --git-dir/--work-tree, say) is the
// reason we remember the environment at all: nothing in the path leads to its
// git dir. On failure we put back what the repo we're staying in needs.
func (self *ReposHelper) switchToLocation(location types.RepoLocation, errMsg string, contextKey types.ContextKey) error {
	originalPath, err := os.Getwd()
	if err != nil {
		return nil
	}
	originalGitLocationEnvVars := env.GetGitLocationEnvVars()

	env.SetGitLocationEnvVars(location.GitLocationEnvVars)

	msg := utils.ResolvePlaceholderString(self.c.Tr.ChangingDirectoryTo, map[string]string{"path": location.Path})
	self.c.LogCommand(msg, false)

	if err := os.Chdir(location.Path); err != nil {
		env.SetGitLocationEnvVars(originalGitLocationEnvVars)
		if os.IsNotExist(err) {
			return errors.New(errMsg)
		}
		return err
	}

	if err := commands.VerifyInGitRepo(self.c.OS()); err != nil {
		env.SetGitLocationEnvVars(originalGitLocationEnvVars)
		if err := os.Chdir(originalPath); err != nil {
			return err
		}

		return err
	}

	direnvResult := self.logDirenvResult(direnv.Load(self.c.OS().Cmd))

	if err := self.recordDirectoryHelper.RecordCurrentDirectory(); err != nil {
		self.c.Log.Errorf("error recording current directory: %v", err)
	}

View on GitHub (pinned to c477a2959b)

Solutions

  1. Verify the path exists: ls <path> in a shell.
  2. If the repo/worktree was removed deliberately, remove it from lazygit's recent repos (delete the entry in the repos menu) so it stops being offered.
  3. If moved, re-add the new location via 'open recent repo' -> add, or relaunch lazygit from the new path.
  4. For unmounted network paths, remount and retry.
Defensive patterns

Strategy: validation

Validate before calling

// before switching:
if _, err := os.Stat(path); os.IsNotExist(err) {
    // prune the stale recent-repo/worktree entry instead of switching
}

Prevention

When it happens

Trigger: Selecting an entry from the recent-repos menu (pressing '/') or switching to a recorded worktree whose directory was deleted, renamed, or is on an unmounted drive; also stale paths in the state file after an external cleanup.

Common situations: Worktrees removed with 'git worktree remove' outside lazygit while still listed; repos moved or deleted; network-mounted paths temporarily unavailable; stale recent-repos list preserved across machines via dotfile sync.

Related errors


AI-assisted analysis of jesseduffield/lazygit@c477a2959b (2026-08-15). Data as JSON: /api/errors/636d5e89c48ea7e6. Report an issue: GitHub.