user1754606
user1754606

Reputation: 1379

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

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?

Upvotes: 74

Views: 79100

Answers (18)

Cloud Cho
Cloud Cho

Reputation: 1774

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

Upvotes: 0

Ashutosh Pandey
Ashutosh Pandey

Reputation: 33

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

Upvotes: 0

Junak Kibria
Junak Kibria

Reputation: 11

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.

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

Upvotes: 0

Aris
Aris

Reputation: 5057

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

Upvotes: 0

vizz29
vizz29

Reputation: 19

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

Upvotes: 1

Ilyas Assainov
Ilyas Assainov

Reputation: 2070

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

Upvotes: 0

remram
remram

Reputation: 5203

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) .

Upvotes: 73

michael-slx
michael-slx

Reputation: 771

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).

Upvotes: 16

Aggressor
Aggressor

Reputation: 13551

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.

Upvotes: 1

X.Nane
X.Nane

Reputation: 44

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

Upvotes: 1

Menno Bieringa
Menno Bieringa

Reputation: 1275

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.

Upvotes: 3

bobobobo
bobobobo

Reputation: 67224

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

Upvotes: 1

Md. Abutaleb
Md. Abutaleb

Reputation: 1635

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

Upvotes: -1

Michael Dunn
Michael Dunn

Reputation: 86

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 

Upvotes: 2

errogaht
errogaht

Reputation: 303

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

Upvotes: 5

Zenadix
Zenadix

Reputation: 16279

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

Upvotes: 122

Laura Liparulo
Laura Liparulo

Reputation: 2897

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!

Upvotes: 20

Related Questions