plandex-ai/plandex · error

error committing files to git repository for dir: %s, err: %

Error message

error committing files to git repository for dir: %s, err: %v

What it means

After successfully staging, GitAddAndCommit runs GitCommit(dir, message, nil, false) (`git -C dir commit -m msg --allow-empty`) and wraps any failure with this error. Because --allow-empty is used, failure is rarely 'nothing to commit' — it usually indicates a git environment problem in dir.

Source

Thrown at app/cli/lib/git.go:28

	"time"
)

var gitMutex sync.Mutex

func GitAddAndCommit(dir, message string, lockMutex bool) error {
	if lockMutex {
		gitMutex.Lock()
		defer gitMutex.Unlock()
	}

	err := GitAdd(dir, ".", false)
	if err != nil {
		return fmt.Errorf("error adding files to git repository for dir: %s, err: %v", dir, err)
	}

	err = GitCommit(dir, message, nil, false)
	if err != nil {
		return fmt.Errorf("error committing files to git repository for dir: %s, err: %v", dir, err)
	}

	return nil
}

func GitAddAndCommitPaths(dir, message string, paths []string, lockMutex bool) error {
	if len(paths) == 0 {
		return nil
	}

	if lockMutex {
		gitMutex.Lock()
		defer gitMutex.Unlock()
	}

	for _, path := range paths {
		err := GitAdd(dir, path, false)
		if err != nil {

View on GitHub (pinned to e2d772072e)

Solutions

  1. Check the wrapped output for the exact git error (GitCommit includes CombinedOutput).
  2. Configure git identity if missing: git config --global user.name / user.email.
  3. Remove a stale lock: rm <dir>/.git/index.lock (only when no git process is running).
  4. Fix ownership/permissions on <dir>/.git and retry the operation.

Example fix

// before
*** Please tell me who you are.  # commit fails
// after
git config --global user.name "You"
git config --global user.email "you@example.com"
Defensive patterns

Strategy: validation

Validate before calling

// Ensure git identity exists before committing
cmd := exec.Command("git", "config", "--global", "user.email")
if err := cmd.Run(); err != nil {
    // configure user.name/user.email before GitAddAndCommit
}

Type guard

func isGitCommitError(err error) bool {
    return err != nil && strings.Contains(err.Error(), "error committing files to git repository")
}

Try / catch

if err := lib.GitAddAndCommit(dir, msg, true); err != nil {
    if isGitCommitError(err) {
        log.Printf("git commit failed in %s: %v (check identity/index.lock)", dir, err)
        return
    }
    return err
}

Prevention

When it happens

Trigger: git commit failing due to missing/invalid user.name/user.email config, a stale .git/index.lock from a concurrent git process, a corrupted repository, or dir being read-only.

Common situations: Fresh machines or CI containers without git identity configured; two Plandex processes colliding on index.lock; .git owned by another user after sudo usage; detached/unusual repo states after crashes.

Related errors


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/ee26c382e549de80. Report an issue: GitHub.