How to resolve Git error insufficient permission for adding an object to repository database


Category: git

When working on a GitHub repo from different Linux hosts, I encountered an "insufficient permission" error when using git commands. Here is the solution that worked for me from StackOverflow.

Sections

  1. The error
  2. The fix
  3. References

The error

You’re working on a local version of a GitHub repo, and you use a command like git add . or git pull you are hit with this error:

insufficient permission for adding an object to repository database

Coming from only working with Git and GitHub from Windows, I first encountered this on Linux when I switched to Debian KDE desktop as my daily driver. My google searching took me to this thread on Stack Overflow where an explanation and solution for the error were provided.

The fix

Information

This solution is credited to user Eric Leschinski in StackOverflow.

This error occurs because you accidentally committed a file or folder to git using elevated permissions and now git can’t modify those objects. It is safe to recursively force ownership of all files under .git/objects/ to your current user to clear the problem.

  1. Make sure you’re inside the repository where you’re getting the error.

  2. Get your username by typing whoami.

  3. Enter this command: sudo chown -R your_user_name .git/*.

  4. Proceed to use your git commands.