fatal: could not open '.git/COMMIT_EDITMSG': Permission denied
Asked Answered
C

18

70

I am trying to deploy octopress on github pages. I followed these instructions:

http://octopress.org/docs/deploying/github/

It all worked well until the commit part, where I get error:

fatal: could not open '.git/COMMIT_EDITMSG': Permission denied

I am the owner of my github.io page, of course, and I never had this issue before. Why is this happening, and more importantly how do I resolve it?

Charades answered 11/11, 2013 at 22:18 Comment(2)
are you c# user by any chance? or having a dual boot for win and Linux?Formosa
I solved it by make .git folder shown, it was hidden :-)Hamadryad
U
72

This is not an error message from the remote Git repository, this is a problem with your local files. You probably used git (or rake) as another user (such as root) in this same directory, and it created files which you now can't overwrite.

Simply use chown to change the ownership of the files to your current user, for instance:

chown -R $(whoami) .
Unmask answered 12/11, 2013 at 1:2 Comment(2)
This is great! Thanks. For macs it can be done like so "sudo chown -R $(whoami) ."Sideling
id -nu or whoami is probably a better option indeed, not certain every chown accepts a numeric user idUnmask
A
114

I solved it by deleting .git/COMMIT_EDITMSG. Weird, I know.

Alba answered 27/10, 2014 at 21:4 Comment(1)
Same, but this kept happening occasionally, I had to go in and set the .git folder and all subfolders as writable (uncheck read-only)Moton
U
72

This is not an error message from the remote Git repository, this is a problem with your local files. You probably used git (or rake) as another user (such as root) in this same directory, and it created files which you now can't overwrite.

Simply use chown to change the ownership of the files to your current user, for instance:

chown -R $(whoami) .
Unmask answered 12/11, 2013 at 1:2 Comment(2)
This is great! Thanks. For macs it can be done like so "sudo chown -R $(whoami) ."Sideling
id -nu or whoami is probably a better option indeed, not certain every chown accepts a numeric user idUnmask
T
19

If you are working on the bloody Microsoft Windows the error might be due to the fact that you are "watching" the hidden files in the file explorer..that´s it!

Telegraphone answered 5/5, 2014 at 13:8 Comment(2)
This was my problem. I had to actually stop showing the hidden files - just closing file explorer didn't work.Tsaritsyn
I've only have set to show hidden files and it was cousing the same xDHorrified
D
15

If you are using Windows and you are stuck with any Git permission issues, make sure your (local) repository's .git folder contents are not marked as hidden.

You can however hide the directory itself, just not it's contents (files, subdirectories).

Dynast answered 26/2, 2019 at 9:13 Comment(0)
S
5

another solution for Windows users: if you are using YandexDisk - and your .git folder under syncronisation - YandexDisk set hidden and readonly attributes after syncronisations. So, switch off YandexDisk and make .git folder and all subfolders and files NOT invisible and not readonly

Solana answered 15/5, 2015 at 6:55 Comment(1)
I just had my files read only because I burned and copy them with CDs. after removing the readonly attribute from all git files (using some c# code to automate it) all worked well.Deep
C
3

This tends not to be a permissions issue.

This situation may occur when you are prompted to record a commit message when merging (for example) and you don't save and quit the text editor but you simply quit.

Git seems to assume there is still someone editting a commit message and refuses to overwrite the existing file as it would cause unexpected behaviour and loss of another commit message.

Coattail answered 13/12, 2016 at 17:18 Comment(0)
P
2

chmod 664 the file .git/COMMIT_EDITMSG gives it group write permissions.

In my situation the file was owned by another user who was part of my development group. Giving it group write permissions solved it.

The .git directory should be in the root of your repository.

Command (assuming you are in the .git directory):

chmod 664 COMMIT_EDITMSG 
Progenitor answered 19/11, 2015 at 16:57 Comment(0)
M
1

If you're using TortoiseGit, you may have a Commit dialog already open

Mcafee answered 21/2, 2016 at 6:6 Comment(0)
T
1

In my case, the reason is that the current user(A) is not COMMIT_EDITMSG file owner(B), change current user to B and commit again. sudo su B

Tiphanie answered 11/10, 2017 at 9:43 Comment(0)
I
1

Quick note:

If you have set a file to hidden/readonly this can occur to. Try setting the whole folder to unhidden and uncheck readonly.

Impregnate answered 23/7, 2018 at 1:44 Comment(0)
D
1

If you are using linux. go to

cd /applicationname/.git
ls -al

You will see user of COMMIT_EDITMSG file

Go to root directory

sudo su
chown youruser: COMMIT_EDITMSG

You are all set! Hope this helps

Demise answered 26/5, 2020 at 2:56 Comment(1)
Thank you! This way solute my problemDoordie
R
0

I had a similar issue on Windows while running Visual Studio and File Explorer. Closing them resolved the issue.

Rakeoff answered 10/3, 2020 at 5:37 Comment(0)
G
0

I am using Ubuntu Linux. For some reason my COMMIT_EDITMSG file was owned by root user. I don't understand why, as it was working before, and I committed without issues.

-rw-r--r--  1 root      root           21 Απρ   3 23:06 COMMIT_EDITMSG

As other people above have said, you need to change ownership to current user. For my case it was:

sudo chown -R your_user.www-data .git
Genniegennifer answered 5/4, 2021 at 19:12 Comment(0)
I
0

If you are using windows, try out one of the following methods.

  1. If the .git folder is hidden , then unhide it and its contents

  2. Go to your .git folder and delete the "COMMIT_EDITMSG" file

Intestine answered 29/10, 2021 at 16:48 Comment(2)
Should I apply the both or either method?Hotshot
Should work for either method. But, you can apply both and check too.Intestine
D
0

This happened to me cause I accidently made my repository folder hidden from windows explorer attributes option and later uncheck the hidden attribute. Probably, these actions made the .git folder files changed in some way. But deleting the COMMIT_EDITMSG file solved it later on.

Dank answered 6/1, 2022 at 11:39 Comment(0)
M
0

If you are using Windows and getting this error: Follow these steps:

.git >> [Right Click] >> Properties >> Uncheck Hidden Value >> Apply changes to this and subfolders >> Apply
Monastery answered 13/6, 2023 at 18:8 Comment(0)
H
0

In my case, it was due to the Git version difference. It happened at the version 1.8.3. I changed the Git version to 2.18.4 using scl enable rh-git218 bash. This command also switches your account to "root". I guess that the cause would be different Git version between my computer and GitHub. Here is a few facts related to the version.

The reason using command line is that somehow I couldn't set 2.18.4 version as default even I installed her.

Runtime environment:
  Operating System: CentOS 7.9

Hotshot answered 3/10, 2023 at 18:21 Comment(0)
C
-1

Simply run on your command line : chmod 777 -Rf /var/www/html/project-name/.git

Critter answered 15/1, 2016 at 21:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.