plandex-ai/plandex · error
error adding file %s to git repository for dir: %s, err: %v
Error message
error adding file %s to git repository for dir: %s, err: %v
What it means
GitAddAndCommitPaths stages each specific path in dir with GitAdd(dir, path, false) and wraps a per-file failure with this message, naming the offending path. Unlike the whole-tree variant, a single bad path (deleted, ignored with constraints, or outside the repo) aborts the whole add loop before commit.
Source
Thrown at app/cli/lib/git.go:47
}
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 {
return fmt.Errorf("error adding file %s to git repository for dir: %s, err: %v", path, dir, err)
}
}
err := GitCommit(dir, message, paths, false)
if err != nil {
return fmt.Errorf("error committing files to git repository for dir: %s, err: %v", dir, err)
}
return nil
}
func GitAdd(repoDir, path string, lockMutex bool) error {
if lockMutex {
gitMutex.Lock()
defer gitMutex.Unlock()
}
res, err := exec.Command("git", "-C", repoDir, "add", path).CombinedOutput()View on GitHub (pinned to e2d772072e)
Solutions
- Check the wrapped error for the named path; verify it exists with ls and is inside dir.
- If the file was deleted intentionally, remove it from the paths list (or recreate it) before committing.
- Use repo-relative paths rather than absolute paths when building the paths slice.
- Confirm `git -C <dir> add <path>` manually reproduces/resolves the issue (e.g. .gitignore rules or submodule problems).
Example fix
// before
paths := []string{"/abs/path/context/file.ts"} # outside repo
// after
rel, _ := filepath.Rel(dir, absPath)
paths := []string{rel} # e.g. "context/file.ts" Defensive patterns
Strategy: validation
Validate before calling
// Filter paths to those that exist and are inside the repo before committing
func validPaths(dir string, paths []string) []string {
var out []string
for _, p := range paths {
if !filepath.IsAbs(p) {
if _, err := os.Stat(filepath.Join(dir, p)); err == nil {
out = append(out, p)
}
}
}
return out
} Type guard
func isGitAddPathError(err error) bool {
return err != nil && strings.Contains(err.Error(), "error adding file ")
} Try / catch
if err := lib.GitAddAndCommitPaths(dir, msg, paths, true); err != nil {
if isGitAddPathError(err) {
// parse the offending path from the message and drop/recreate it
log.Printf("git add failed for a specific path: %v", err)
return
}
return err
} Prevention
- Use repo-relative paths, not absolute paths, when calling GitAddAndCommitPaths.
- Skip paths that no longer exist on disk instead of failing the whole batch.
- Re-verify file existence after rewind/apply operations that may delete files.
- Check .gitignore/submodule rules for paths git refuses to add.
When it happens
Trigger: Calling GitAddAndCommitPaths (e.g. from rewind or commitApplied) with a path that no longer exists on disk, lies outside the repository root, is an ignored submodule path, or when dir is not a git repository.
Common situations: Rewinding/committing after a file was deleted externally; path casing mismatches; passing absolute paths while git -C expects repo-relative ones; plan context referencing files removed between operations.
Understand the failure class
Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.
Related errors
- error adding files to git repository for dir: %s, err: %v
- error getting git root: %s
- error getting git status: %s
- error getting files in git repo: %s
- error getting untracked files in git repo: %s
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/07776cb795ecb9d5.
Report an issue: GitHub.