[git] Git Checkout warning: unable to unlink files, permission denied

I am aware that there are similar issues about git relating to the 'unable to unlink' warning, but I have not been able to use them.

The main difference is that this happened when I have not been dealing with submodules in any way (I have never dealt with them before). I created a branch called 'upgrade', deleted my old framework files, and copied in the new ones. I used git add -A, then committed everything. When I tried to checkout the trunk branch, it responded with the following errors:

warning: unable to unlink requirements/views/sk/index.php: Permission denied
warning: unable to unlink requirements/views/sv/index.php: Permission denied
warning: unable to unlink requirements/views/zh/index.php: Permission denied
warning: unable to unlink requirements/views/zh_cn/index.php: Permission denied
warning: unable to unlink requirements/views/zh_tw/index.php: Permission denied

...etc. There are hundreds of them.

At first I thought this was simply a permissions problem, and so I added group write permissions to the entire requirements directory recursively, but there was no change.

Edit: As suggested in an answer below, I attempted to do the same thing but with everything else closed. I had no more luck than before.

This issue is particularly debilitating as I cannot move to trunk to get back to normal development.

This question is related to git

The answer is


In my case the permission problem solved by setting www-data as an owner:

chown -R www-data project_folder_name

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.


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

To those who are using Intellij, as @rtconner said this problem is not caused by git. Since your IDE is locked a file(s) git cannot un-link it. So, you need to close your IDE and then try to merge (or whatever you like) it via command line.


This can also occur when:

  1. You ran a process inside a Docker container, and:

  2. Some files were generated by that process, and:

  3. The destination of the files is mounted as a volume on the Docker host, and:

  4. You are running git on the Docker host.


If this is the case, stage the files you wish to commit and run:

git diff --name-only --cached | xargs ls -l 

Files which meet the above criteria will be prefixed with:

-rw-r--r-- 1 root root ...

They are owned by root and not writable, which is not good. To fix that run:

 git diff --name-only --cached | xargs -i sh -c 'sudo chown $USER:$USER {}; chmod +w {}'

A cleaner solution would probably be to use the --user option, see this for Docker and this for Docker compose.


I encountered this error and I think the issue was that I had 'run as admin' when I started Eclipse and created the files, therefore they were owned by Admin (noticed by running 'ls -la' on the folder). When I later tried to stash the files, it didn't let me ('unable to unlink files' and all that). Doing a chmod on the files was the fix for me.


In my case, my Windows directory is under the Dropbox folder. It is not a Git-specific issue. When a file (in this case, the lock file) has just been created, it takes Dropbox another second to do the synchronization. During that time, the file is in use by Dropbox, and any 3rd party program (in this case, Git) cannot delete the file.

My solution is to quit Dropbox and therefore avoiding the behind-the-scenes magic of Dropbox's file synch.


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.


I just had to switch user from ubuntu to my actual user name that I'd first done stuff under. That fixed it.


Solved for me by setting my git client (GitExtensions) to always run in admin mode.


All you need to do is provide permissions, run the command below from the root of your project:

    chmod ug+w <directory path>

I've encountered this error while running Git Bash on a windows box. In my particular case I just needed to open Git Bash as administrator.


I had that problem while using IntelliJ (14.1.3 Ultimate), I wanted to revert changes in some file.

Solved by closing Git Bash opened in another window - another revert trial in IntelliJ worked.


I had the same issue , I tried few alternatives as others suggested.

But finally giving correct permission to .git folder solve the issues.

sudo chown -R "${USER:-$(id -un)}" .git

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.


on terminal on mac i just do this

sudo git checkout . ( to clean up everything )

and then

sudo git pull origin


Just in general, if this happens in Windows, and you are using tortoisegit, it is the status cache of tortoisegit. Kill that process and it will be freed.


git gc worked for me (in a new tab). Was getting this with every rebase. Thanks http://www.saintsatplay.com/blog/2016/02/dealing-with-git-unlink-file-errors#.W4WWNZMzZZJ


I had this error inside a virtual machine (running Ubuntu), when I tried to do git reset --hard.

The fix was simply to run git reset --hard from the OS X host machine instead.


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


I have encountered this error and it is caused by wrong "owner/group" of the file/folder. You must seek assistance to your server admin to change the "owner/group" of this file/folder and retry using "git pull" again. Or if you are a sudoer, just sudo chown "your owner name / your group name" and try again pulling your repository. Try it, it works 100% to me!


Make sure that any associated processes or threads are not running and perform end task or force quit as necessary.

Make sure you change the ownership permission.


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.


None of the other suggestions worked for me, but this did:

sudo git reflog expire --expire=now --all && sudo git gc --prune=now --aggressive


In my case it was a ":" character in a folder name prevenitng the git repo to checkout on windows.