Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git Checkout warning: unable to unlink files, permission denied

Tags:

git

In my first encounter with this error my user had rights to "write" to the file but not the containing directory. Check the permissions of the directory containing the file.


I usually see that kind of error when there is a process not releasing the handle of those files.

Make sure nothing is running, and then try your checkout again.

Note: it can also be related with the way Git has been installed (on Windows, UAC can generate problem if msysgit is installed in C:\Program or C:\Program Files, see "msysgit - sh.exe - fork: Permission denied - Vista 64 bit" and comment 2 of issue 437)

Note: as illustrated below, a common other cause of the problem is rights issue on the directory (wrong owner), not necessarily on the file that can't be unlinked.


"Unlink" essentially means "delete file" in this case.

This error is not caused by git itself. You should have similar errors deleting those files manually, in a command line or file explorer.


You don't have the access permission, maybe because you are not the owner.

Fix by changing the owner to yourself:

sudo chown -R your_login_name /path/to/folder

I was having the issue with a default-settings.php file in drupal 7. In this case I wasn't able to delete it or revert it just like @rtconner said. I didn't have an application or anything using this file, and it ended up being a permissions error.

I added chmod 777 * to the folder and then I was able to revert it no problem.


You can change the write permissions to get it done.

sudo chmod -R ug+w . 

This command will give 'w' permissions to all the folders in the current directory.


I ran into this problem whenever running "git repack" or "git gc" on my OS X machines, even when running git with admin privileges, and I finally solved it after coming across this page: http://hints.macworld.com/comment.php?mode=view&cid=1734

The fix is to open a terminal, go to your git repo, cd into the .git folder, and then do:

chflags -R nouchg *

If that was the issue, then after that, your git commands will work as normal.