54

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

3
  • 1
    try git fetch && git checkout develop.
    – Shravan40
    Commented Jul 25, 2016 at 8:06
  • Check this link it has 2-3 solutions for the same issue stackoverflow.com/questions/12077605/…
    – Bhavesh
    Commented Jul 25, 2016 at 9:05
  • 3
    For me it was a Visual Studio debugging session.
    – yoyo
    Commented Jul 19, 2017 at 16:00

16 Answers 16

60

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.

5
  • 3
    Quite often node processes can continue to run in the background, especially on windows machines. in this case try killall node in bash will stop all node process whilst releasing any file locks they have.
    – Christo
    Commented Sep 25, 2018 at 8:19
  • I've closed the nodeJs server where my angularJs app was running and the index was unlocked
    – Radu Linu
    Commented Oct 19, 2018 at 9:42
  • 1
    Same issue but I did not have any error showing up in the console, just the app running. Thanks.
    – Louis
    Commented Nov 29, 2018 at 9:01
  • 1
    You are a superhero! I am running npm run watch when I got this!
    – Player1
    Commented Dec 17, 2018 at 18:40
  • seems also having sourcetree monitoring the repo could cause this
    – netalex
    Commented Feb 22, 2019 at 9:48
15

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>
1
  • 1
    this is the real solution to the problem I had. for some reason the system user I was using to try to pull from GitHub, didn't have permission to write to that specific path, thank you!!
    – Carlos
    Commented Mar 2, 2023 at 15:18
14

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.

0
7

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.

4

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.

3

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

3

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
1

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

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

0

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.

0

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.

0
0

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

0

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

0

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.

0

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.

0
-1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.