65

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?

user1754606
  • 1,259
  • 2
  • 13
  • 18

17 Answers17

108

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

Zenadix
  • 15,291
  • 4
  • 26
  • 41
70

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) .
remram
  • 4,805
  • 1
  • 29
  • 42
  • 5
    This is great! Thanks. For macs it can be done like so "sudo chown -R $(whoami) ." – Brian Rizo Oct 26 '17 at 19:12
  • `id -nu` or `whoami` is probably a better option indeed, not certain every `chown` accepts a numeric user id – remram Oct 26 '17 at 19:42
  • You Sir is perfect. I always stuck when moving rails projects from one ubuntu system to another and after wasting couple of hours and even whole day I somewhat able to fix it but today I finally got what I should need to do in order to fix the issue for whole projects and infact the directory having all projects. Thanks a lot..!!!! –  Apr 17 '18 at 15:29
  • 1
    It's `chown -R $(whoami) .` on macOS – Pavan Jadda Apr 30 '19 at 03:01
  • Thanks, updated. Indeed the long options are probably unique to GNU – remram May 01 '19 at 09:57
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!

Laura Liparulo
  • 2,849
  • 26
  • 27
  • 2
    Setting up a bloody Windows machine to test out some code, and wasted like ton of energy on this type of things. Why, why, why I have to ask, with their hoard of developers, can't they make things just work out of the box, really? – Eduardo in Norway Sep 10 '15 at 14:26
  • 3
    This was my problem. I had to actually stop showing the hidden files - just closing file explorer didn't work. – VSO Nov 29 '17 at 22:29
  • I've only have set to show hidden files and it was cousing the same xD – z48o0 Nov 06 '21 at 05:29
12

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

michael-slx
  • 665
  • 9
  • 15
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

errogaht
  • 303
  • 1
  • 4
  • 12
  • 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. – YoniXw May 29 '17 at 06:12
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.

Menno Bieringa
  • 1,215
  • 12
  • 17
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 
Maxime Rouiller
  • 13,614
  • 9
  • 57
  • 107
Michael Dunn
  • 86
  • 2
  • 3
1

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

bobobobo
  • 64,917
  • 62
  • 258
  • 363
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

X.Nane
  • 46
  • 2
  • 8
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.

Aggressor
  • 13,323
  • 24
  • 103
  • 182
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

vizz29
  • 19
  • 6
1

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.

0

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

Ilyas Assainov
  • 1,901
  • 13
  • 15
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
Aris
  • 4,643
  • 1
  • 41
  • 38
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

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

desertnaut
  • 57,590
  • 26
  • 140
  • 166
-1

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

Md. Abutaleb
  • 1,590
  • 1
  • 14
  • 24