git submodule update failed with 'fatal detected dubious ownership in repository at...'
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Git 2.35.2+ introduced a security check that refuses to operate on repositories owned by a different user than the current one. When running git submodule update, this check applies to each submodule directory, and if the submodule is owned by a different OS user (common in Docker containers, CI/CD pipelines, and shared file systems), Git throws fatal: detected dubious ownership in repository at. The fix is to add the directory to Git's safe.directory list or fix the actual file ownership.
The Error
This error means the submodule directory is owned by a different user than the one running the git command.
Why This Exists
Git added this check in response to CVE-2022-24765. Without it, a malicious user could place a .git directory in a shared location (like /tmp) and configure Git hooks that execute arbitrary code when another user runs git commands in that directory. The ownership check prevents Git from trusting repositories owned by other users.
Fix 1: Add safe.directory (Quick Fix)
This tells Git to trust the directory even though it is owned by another user.
Fix 2: Fix File Ownership (Proper Fix)
This is the correct fix when you actually own the repository and the ownership was wrong (e.g., after extracting an archive as root).
Fix 3: Docker Containers
This error is extremely common in Docker because files mounted from the host or created by different users inside the container have mismatched ownership.
Fix 4: CI/CD Pipelines
GitHub Actions
GitLab CI
Jenkins
Automating safe.directory for All Submodules
Checking Your Git Version
The ownership check was introduced in Git 2.35.2. If you cannot fix the ownership and safe.directory is not available:
Common Pitfalls
- Using
safe.directory '*'in production: The wildcard disables ownership checks globally, defeating the security purpose. Use it only in ephemeral environments like CI containers. In production, add specific paths. - Forgetting recursive submodules: If submodule A contains submodule B, you must add both paths to
safe.directory. Usegit submodule foreach --recursiveto add all of them automatically. - Setting safe.directory in the wrong Git config scope:
--globalsets it for the current user. In Docker containers running as root, this configures root's gitconfig. If the container later switches users, the setting is lost. Use--systemfor container-wide settings. - Fixing ownership in a mounted volume:
chowninside a Docker container does not change ownership on the host when using bind mounts on Linux. The files remain owned by the host user. Useuser:in docker-compose.yml to match the host UID instead. - Not understanding the security implication: The error exists to prevent code execution attacks via malicious
.gitdirectories. Before addingsafe.directory, verify that the repository is actually trusted and the ownership mismatch is benign (Docker, CI) rather than a sign of compromise.
Summary
- Git 2.35.2+ refuses to operate on repositories owned by a different user (CVE-2022-24765 fix)
- Quick fix:
git config --global --add safe.directory /path/to/repo - Proper fix:
chown -R $(whoami) /path/to/repoto correct ownership - Docker containers: add
safe.directoryin the Dockerfile or match UIDs withuser:in compose - CI/CD: add
safe.directoryfor$GITHUB_WORKSPACEor $CI_PROJECT_DIRin pipeline config - Avoid
safe.directory '*'outside of ephemeral, trusted environments

