How to fix error: insufficient permission for adding an object to repository database .git/objects in Git
Git can't write to .git/objects due to root-owned files. Fix by running sudo chown -R $USER:$USER .git to restore ownership.
Quick fix
Fixes EACCES
ls -la .git/objects/- Check ownership of .git/objects directory
- Fix ownership recursively
- Verify the fix
- Configure shared repository for multi-user setups
ls -la .git/objects/error: insufficient permission for adding an object to repository database .git/objects
What this error means
When you run a Git operation (push, pull, commit, fetch), Git needs to store objects (blobs, trees, commits) in the `.git/objects` directory. This error appears when your current user lacks write permission to that directory or its contents. The root cause is almost always a **permission mismatch**: some files in `.git/objects` are owned by a different user (typically root) than your current user. This commonly happens when you: 1. Run `git` commands with `sudo` by mistake 2. Have multiple users working on the same repository 3. Run Git operations inside Docker containers as root while the host filesystem is mapped 4. Use CI/CD pipelines where the build agent runs as a different user This is not a Git bug but a filesystem permission issue. Git is simply respecting Unix permission semantics—if you don't own the file, you cannot write to it.
Typical symptoms
- Git push fails with 'insufficient permission for adding an object'
- Git pull or fetch operations fail with object database errors
- Git commit fails when trying to store new objects
- The error references .git/objects directory specifically
- Operations work when run with sudo but fail as regular user
- CI/CD pipelines fail at Git operations after working previously
- The error appears after accidentally running git with sudo
Common causes
- Accidentally ran git commands with sudo, creating root-owned files (most common)
- Multiple users working on the same repository with different UIDs
- Git operations inside Docker containers created files as root
- Repository cloned or initialized by a different user
- CI/CD pipeline running as a different user than expected
- Mounted filesystems (NFS, CIFS) with incorrect ownership mapping
- WSL1 filesystem mounting issues (resolved in WSL2)
How to fix "error: insufficient permission for adding an object to repository database .git/objects"
First, examine the permissions and ownership of your Git objects directory:
ls -la .git/objects/Look for files or directories owned by root or another user. You'll see output like:
drwxr-xr-x 2 root root 4096 Jan 15 10:30 pack
drwxr-xr-x 2 youruser youruser 4096 Jan 15 10:28 infoIf you see mixed ownership, that's the problem.
The standard fix is to change ownership of the entire .git directory to your current user:
sudo chown -R $(whoami):$(whoami) .git/Or more explicitly:
sudo chown -R $USER:$USER "$(git rev-parse --show-toplevel)/.git"This recursively changes all files and directories under .git to be owned by your user.
For specific objects directory only:
sudo chown -R $(id -un):$(id -gn) .git/objects/After changing ownership, verify the operation now works:
# Check ownership is correct
ls -la .git/objects/
# Test a Git operation
git status
git fetchIf you were trying to push, retry:
git push origin mainIf multiple users need to access the same repository, configure Git to manage permissions automatically:
git config core.sharedRepository groupThis tells Git to make new objects group-writable. For new repositories, initialize with:
git init --shared=groupAvailable sharing modes:
- group (or true): Group-writable, allows users in the same group to push
- all (or world): Readable by all users, group-writable
- umask (or false): Use default umask (default behavior)
- 0xxx: Explicit octal permission mode
For repositories shared between multiple users, ensure proper group setup:
# Create a dedicated group (if needed)
sudo groupadd gitusers
# Add users to the group
sudo usermod -aG gitusers alice
sudo usermod -aG gitusers bob
# Change group ownership of the repository
sudo chgrp -R gitusers .git/
# Make existing files group-writable
sudo chmod -R g+rwX .git/
# Set the setgid bit so new files inherit the group
find .git -type d -exec chmod g+s {} +Users may need to log out and back in for group changes to take effect.
Advanced notes
### Docker Container Issues
When running Git inside Docker containers with mounted volumes, the container often runs as root while your host filesystem belongs to your regular user. Solutions:
1. Run container as your user:
docker run --user $(id -u):$(id -g) -v $(pwd):/repo myimage git pull2. Use a non-root user in Dockerfile:
RUN useradd -m appuser
USER appuser### WSL1 vs WSL2
On WSL1, mounted Windows filesystems (like /mnt/c/) have known permission issues that cause this error. The recommended solution is to upgrade to WSL2:
wsl --set-version Ubuntu 2### Bare Repositories (Git Servers)
For bare repositories used as Git servers, always initialize with shared permissions:
git init --bare --shared=group /srv/git/myproject.git### NFS/Network Filesystems
On NFS mounts, ensure:
1. UID/GID mapping is consistent between client and server
2. The no_root_squash option is NOT set unless absolutely necessary
3. Consider using git config core.sharedRepository group for multi-user access
### Preventing Future Issues
Add a pre-commit hook to warn about sudo usage:
# .git/hooks/pre-commit
if [ "$(id -u)" = "0" ]; then
echo "WARNING: Running git as root. This may cause permission issues."
fi### CI/CD Pipelines
Ensure your CI runner user owns the workspace:
# GitLab CI example
before_script:
- sudo chown -R $(whoami) .Frequently asked questions
- What does "EACCES" mean?
- git/objects directory. This error appears when your current user lacks write permission to that directory or its contents. git/objects are owned by a different user (typically root) than your current user.
- How do I fix "EACCES"?
- Git can't write to .git/objects due to root-owned files. Fix by running sudo chown -R $USER:$USER .git to restore ownership.
- What causes "EACCES"?
- Accidentally ran git commands with sudo, creating root-owned files (most common) Multiple users working on the same repository with different UIDs Git operations inside Docker containers created files as root
- Is the "EACCES" error serious?
- It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- 📚Git Official Documentation
- 📖git-init Documentation - --shared option(Official Docs)
- 📖git-config Documentation - core.sharedRepository(Official Docs)
- 💬
- 💬
- 💬
- 🐙
- 🐙