jesseduffield/lazygit · error
While attempting to write back migrated user config to %s, a
Error message
While attempting to write back migrated user config to %s, an error occurred: %s
What it means
Raised in pkg/config/app_config.go:268 during automatic user config migration. lazygit detected that the config file needs a schema migration, computed the migrated YAML content, but os.WriteFile to the config path failed (permissions, missing parent dir, read-only filesystem). The error includes the path and the underlying write error; in GUI mode the pending changes text is appended so the user can apply it manually.
Source
Thrown at pkg/config/app_config.go:268
return content, nil
}
changesText := "The following changes were made:\n\n"
changesText += strings.Join(lo.Map(changes.ToSliceFromOldest(), func(change string, _ int) string {
return fmt.Sprintf("- %s\n", change)
}), "")
// Write config back
if !isGuiInitialized {
fmt.Printf("The user config file %s must be migrated. Attempting to do this automatically.\n", path)
fmt.Println(changesText)
}
if err := os.WriteFile(path, changedContent, 0o644); err != nil {
errorMsg := fmt.Sprintf("While attempting to write back migrated user config to %s, an error occurred: %s", path, err)
if isGuiInitialized {
errorMsg += "\n\n" + changesText
}
return nil, errors.New(errorMsg)
}
if !isGuiInitialized {
fmt.Printf("Config file saved successfully to %s\n", path)
}
return changedContent, nil
}
// A pure function helper for testing purposes
func computeMigratedConfig(path string, content []byte, changes *ChangesSet) ([]byte, bool, error) {
var err error
var rootNode yaml.Node
err = yaml.Unmarshal(content, &rootNode)
if err != nil {
return nil, false, fmt.Errorf("failed to parse YAML: %w", err)
}
var originalCopy yaml.Node
err = yaml.Unmarshal(content, &originalCopy)
if err != nil {View on GitHub (pinned to c477a2959b)
Solutions
- Fix ownership/permissions: 'chown -R $USER ~/.config/lazygit' and ensure write access (chmod u+w)
- Free disk space or remount the config location read-write
- Re-run lazygit from a terminal (isGuiInitialized=false) so the changes text prints to stdout, and apply the migration by hand
- Back up then delete the stale config so lazygit regenerates defaults, then reapply custom settings
Example fix
# shell fix, not a code fix sudo chown -R $(whoami) ~/.config/lazygit chmod u+w ~/.config/lazygit/config.yml
Defensive patterns
Strategy: validation
Validate before calling
// Pre-flight check before launching lazygit across an upgrade:
func configWritable(path string) error {
info, err := os.Stat(filepath.Dir(path))
if err != nil {
return err
}
if info.Mode().Perm()&0o200 == 0 {
return fmt.Errorf("config dir %s is not writable", filepath.Dir(path))
}
return nil
} Try / catch
if _, err := loadConfig(); err != nil && strings.Contains(err.Error(), "write back migrated user config") {
// apply printed changesText manually after fixing permissions
fmt.Println(err)
} Prevention
- Never run lazygit under sudo; fix ownership with chown if you did
- Keep the config dir writable and backed up before upgrades
- Run lazygit in a terminal when migrating so changesText prints for manual recovery
When it happens
Trigger: os.WriteFile(path, changedContent, 0o644) failing: config dir owned by another user, config on a read-only mount, disk full, SELinux/AppArmor denial, or the file being immutable.
Common situations: Running lazygit with sudo previously so ~/.config/lazygit is root-owned; corporate machines with enforced read-only home subpaths; config synced via a tool that locks the file; upgrading lazygit across a version that introduced a config migration.
Related errors
- You should have an allBranchesLogCmds defined as a sequence!
- Feature not available for users using GPG. If you are using
- Feature not available for users using GPG. If you are using
- Unsupported git service
- gui.sidePanels: a side panel must have at least one tab.
AI-assisted analysis of jesseduffield/lazygit@c477a2959b (2026-08-15).
Data as JSON: /api/errors/4ff05d32c54228da.
Report an issue: GitHub.