Search code examples
macosgithubnpmvisual-studio-codefile-permissions

'Unable to create file ... Operation not permitted' when cloning a repo from GitHub


As the title says, I am trying to clone one of my GitHub repos in VSCode. I am getting the following error:

fatal: Unable to create temporary file '/Users/user/Documents/Projects/MyGamesList/MyGamesList/.git/objects/pack/tmp_pack_XXXXXX': Operation not permitted

I am cloning this repo after deleting the local files of the repo because I was faced with a EPERM Operation not permitted when trying to use npm start.

I am on macOS Big Sur 11.4. I have tried altering the permissions for my documents folder and updating NPM.


Solution

  • In general, you don't want to put Git repositories in the macOS Documents folder. What you're likely seeing is that macOS restricts access to that folder to certain programs based on permissions that are outside the normal Unix framework. As a result, you can often see EPERM in these cases.

    While it is possible to grant Git and npm access to modify data in Documents, because Git still has commands written in Perl and shell, you also need to grant access to every Unix command-line tool as well, which is inconvenient.

    In addition, the Documents folder is sometimes synced via iCloud, and you should refrain from storing Git repositories in directories synced by iCloud or similar file-based syncing services since it can cause repostory corruption.

    If you move your Projects folder out of Documents into your home directory, things should work just fine.