pop_up
pop_up

Reputation: 1579

unable to create file ... Permission denied

i am currently working on windows.

Sometimes i have problems when i try :

git checkout origin develop

i have this error : error: unable to create file .... : Permission denied

"git status" show me the file in error not staged so i have to commit

What do i have to check ?

i tried to do this command line on my computer :

chown -R username directory

We are severals people to work on a git repository and they have the problem too.

thanks for you help

Upvotes: 56

Views: 100327

Answers (16)

xiaowei hou
xiaowei hou

Reputation: 1

The file or directory is currently in use by another program. Please close all applications accessing it. If the issue persists, restarting your system may resolve the problem.

Upvotes: 0

Josiel Faleiros
Josiel Faleiros

Reputation: 1477

I'm using Pop!_OS, got to this question after having the same problem,

For me resolved going to the Terminal, and typing:

sudo chown -R $USER:$USER ~/path-to-problematic-folder

Upvotes: 3

Mohsin Mahmood
Mohsin Mahmood

Reputation: 3436

I figured this out by giving permission to the directory where I wanted to create a file, by using the following command:

sudo chmod a+rwx <path-of-directory>

Upvotes: 16

Remicaster
Remicaster

Reputation: 376

For windows user, if you happen to stumble upon this issue, try check your antivirus.

For me, my issue is that my Avast Antivirus decides that the file is a malware and blocked it, restoring the file via git restore . will result in a permission denied.

What I did is simply add that file as exception and it worked for me.

Upvotes: 0

NickBeaugi&#233;
NickBeaugi&#233;

Reputation: 740

I had this problem when running a bash script in Git Bash.

I could find no way of changing the permissions.

In the end, when I closed the Git Bash window, the file was deleted. It was no problem then to "restore" it by Discarding the change (using Git).

Upvotes: 0

user5305519
user5305519

Reputation: 3226

For me, I made a careless mistake of git pull instead of git clone

Upvotes: -1

Had same problem developing from VS Code Remote-WSL. Tried to kill NodeJS processes but had some open from previous sessions that didn't want to die. At the end had to restart the WSL and happy times.

Restart WSL (mind to save files first if something open in WSL):

In Windows WIN+R -> services.msc -> Find LxssManager -> Right-click -> Restart

Upvotes: 1

gustavoknz
gustavoknz

Reputation: 562

In my case, I had to run git command with sudo: sudo git checkout

Upvotes: 0

SamK
SamK

Reputation: 63

This was happening to me on linux. I just renamed the folder with the offending file and from the top directory of the checkout ran a git checkout . which solved the problem.

Upvotes: 0

JustAnotherGirl
JustAnotherGirl

Reputation: 371

I was facing the same issue. If your code is running, Stop it (i.e close the terminal on which npm run *** is working) and close Visual Studio. Re-open it and again run the command git checkout develop . It worked for me.

Upvotes: 0

kyselm
kyselm

Reputation: 310

None of the provided solutions helped in my case of this problem.

Finally (after many desperate unsuccessful attempts) the thing that did the work was good old PC reboot.

Upvotes: 4

pcpie
pcpie

Reputation: 31

For me it was that I was running npm run watch in a linux subsystem (wsl) running it in a normal cmd fixed it.

Upvotes: 1

Leo
Leo

Reputation: 10833

In my case, my angular app was still running from ng serve, giving this:

Git Bash - ng serve

So I just had to close it with ctrl+c.

Upvotes: 62

ykorach
ykorach

Reputation: 616

In my case, "npm run dev", for webpack build to my React app was still running with failed to compile error. aborting it with ctrl+c fix it

Upvotes: 3

Dave
Dave

Reputation: 1429

I had the same issue and the problem was open files. Make sure you don't have the files git is trying to create open anywhere; close your localhost browser tabs if any of the files are open there; close all references to the files you are working with. That's what worked for me.

Upvotes: 14

Taitu-lism
Taitu-lism

Reputation: 946

First make sure to run your cmd/terminal as an administrator (right click on cmd.exe icon -> "Run as Administrator")

I had the same issue with a git pull (using cmder on windows). What worked for me is this:

This will delete your local changes:
hard reset your branch and try again.
$ git checkout origin develop - (failed)
$ git reset --hard HEAD
$ git checkout origin develop - (great success!)

If this doesn't work try forcing the checkout:
This will also throw away your local changes
$ git checkout -f origin develop.

Upvotes: 7

Related Questions