Software⏱️ 3 min read📅 2026-06-15

How to Fix: Why am I experiencing this error: Git commit could not open '.git/COMMIT_EDITMSG': Permission denied?

Git permission denied error in shared server repo.

Quick Answer: Try changing the ownership of the .git directory to your user ID, or use a different user ID with sudo to commit changes.

The Git commit error 'permission denied' in your own repository on a shared server can be frustrating and may prevent you from making changes to your code. This issue typically occurs when the Git directory is not properly configured, leading to a lack of access permissions.

Changing the ownership or permissions of the `.git` directory might resolve this problem, but it's essential to understand why this error happens in the first place.

🛑 Root Causes of the Error

  • The primary reason for this error is that the Git repository's owner and group do not have sufficient permissions to access the `.git/COMMIT_EDITMSG` file. This can occur if the ownership of the directory has changed or if the permissions are set too restrictive.
  • Another possible cause could be a misconfigured Git configuration, where the `core.editor` setting is pointing to an editor that requires elevated privileges.

🛠️ Step-by-Step Verified Fixes

Changing Ownership and Permissions

  1. Step 1: Open a terminal as the owner of the repository (usually 'yj2429') using the command `sudo su yj2429` or `su yj2429` if you have sudo privileges.
  2. Step 2: Change the ownership of the `.git` directory to your user ID by running the command `chown -R $(whoami) .git`. This will set the correct ownership and ensure that you have access permissions.
  3. Step 3: Verify that the ownership has been successfully changed by checking the output of the `ls -al .git` command. You should see the correct ownership and permissions (in this case, `drwxr-xr-x 13 yj2429 dune 512 Sep 3 11:27 .`).

Modifying Git Configuration

  1. Step 1: Open your repository's `.gitconfig` file using a text editor by running the command `nano ~/.gitconfig`. This will allow you to modify the configuration settings.
  2. Step 2: Locate the `core.editor` setting and change it to an editor that does not require elevated privileges, such as `vi` or `vim`, by adding the following line: `core.editor = vi`. Save the changes when you're done.

💡 Conclusion

To resolve the Git commit error 'permission denied' in your repository, try changing the ownership and permissions of the `.git` directory or modifying the Git configuration to ensure that the editor is set to a non-privileged application. If you are still experiencing issues, consider consulting with your system administrator or seeking further assistance from a Git expert.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions