How to fix error: insufficient permission for adding an object to repository database .git/objects in Git

GitBEGINNERMEDIUMUpdated May 28, 2026· 382 views

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/
  1. Check ownership of .git/objects directory
  2. Fix ownership recursively
  3. Verify the fix
  4. Configure shared repository for multi-user setups
git — error
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

  1. Accidentally ran git commands with sudo, creating root-owned files (most common)
  2. Multiple users working on the same repository with different UIDs
  3. Git operations inside Docker containers created files as root
  4. Repository cloned or initialized by a different user
  5. CI/CD pipeline running as a different user than expected
  6. Mounted filesystems (NFS, CIFS) with incorrect ownership mapping
  7. WSL1 filesystem mounting issues (resolved in WSL2)

How to fix "error: insufficient permission for adding an object to repository database .git/objects"

1Check ownership of .git/objects directory

First, examine the permissions and ownership of your Git objects directory:

bash
ls -la .git/objects/

Look for files or directories owned by root or another user. You'll see output like:

bash
drwxr-xr-x 2 root root 4096 Jan 15 10:30 pack
drwxr-xr-x 2 youruser youruser 4096 Jan 15 10:28 info

If you see mixed ownership, that's the problem.

2Fix ownership recursively

The standard fix is to change ownership of the entire .git directory to your current user:

bash
sudo chown -R $(whoami):$(whoami) .git/

Or more explicitly:

bash
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:

bash
sudo chown -R $(id -un):$(id -gn) .git/objects/
3Verify the fix

After changing ownership, verify the operation now works:

bash
# Check ownership is correct
ls -la .git/objects/

# Test a Git operation
git status
git fetch

If you were trying to push, retry:

bash
git push origin main
4Configure shared repository for multi-user setups

If multiple users need to access the same repository, configure Git to manage permissions automatically:

bash
git config core.sharedRepository group

This tells Git to make new objects group-writable. For new repositories, initialize with:

bash
git init --shared=group

Available 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

5Fix group permissions for shared repositories

For repositories shared between multiple users, ensure proper group setup:

bash
# 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:

bash
docker run --user $(id -u):$(id -g) -v $(pwd):/repo myimage git pull

2. Use a non-root user in Dockerfile:

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:

powershell
wsl --set-version Ubuntu 2

### Bare Repositories (Git Servers)

For bare repositories used as Git servers, always initialize with shared permissions:

bash
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:

bash
# .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:

yaml
# 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