Git's "could not create work tree dir: Permission denied" means it cannot create the clone target folder because your user lacks write access to the parent directory. Fix it by cloning to a directory you own.
When you run `git clone`, Git tries to create a new directory (the "work tree") at the path you specified or in your current working directory. This fatal error appears when your user account does not have write permission on the parent directory where Git is trying to create the repository folder. The message names exactly which directory Git tried to create (in quotes) and reports that the operating system denied the operation. This is a filesystem-level permission error reported by the OS, not a Git-specific bug, so the same failure would occur with a plain `mkdir` in that location. Common scenarios where this occurs: 1. **Cloning into protected system directories** - Attempting to clone into `/`, `/opt`, `/var`, or other root-owned locations. 2. **Incorrect current directory** - Being in a directory you do not have write access to. 3. **Shared servers** - Working on multi-user systems where your home or working directory is misconfigured. 4. **Network-mounted filesystems** - NFS, CIFS, or other mounts with restrictive permissions. 5. **Read-only or full filesystems** - A drive mounted read-only, or a disk-full condition surfacing as a write failure.
First, confirm where you are cloning and whether you can write there:
pwd
ls -la .Look at the owner and permission bits of . (the current directory). If it is owned by root or another user and others have no write bit, that is your problem:
drwxr-xr-x 5 root root 4096 Jan 15 10:00 .Here r-x for "other" (the last three characters) means you can read and execute but not write, so you cannot create a new subdirectory. A quick confirmation:
# Succeeds only if you can write here
mkdir _writetest && rmdir _writetest && echo "writable" || echo "not writable"The simplest and safest fix is to clone somewhere your user owns, such as your home directory:
cd ~
git clone https://github.com/username/repo.gitOr give an explicit target path inside your home directory:
git clone https://github.com/username/repo.git ~/projects/repoA dedicated projects directory keeps things tidy:
mkdir -p ~/projects
cd ~/projects
git clone https://github.com/username/repo.gitIf you genuinely need the repo outside your home directory (for example under /opt), create the directory once with sudo and hand ownership to your user, then clone normally:
# Create the parent directory with sudo
sudo mkdir -p /opt/projects
# Give ownership to your user
sudo chown $USER:$USER /opt/projects
# Now clone runs as your normal user, no sudo needed
git clone https://github.com/username/repo.git /opt/projects/repoImportant: Do not run git clone itself with sudo. That makes the entire repository owned by root and forces every later Git command to need sudo, which leads to more permission problems.
Sometimes a directory you own was previously created or written by root (for example after an earlier sudo git clone or sudo npm install), leaving root-owned files inside. Fix only the affected directory, not your whole home folder.
First, inspect what is actually root-owned so you change the minimum necessary:
# List items in the directory and their owners
ls -la ~/projects
# Find files NOT owned by you under a specific path
find ~/projects -not -user "$USER" -printThen correct ownership for just that path:
sudo chown -R "$USER:$USER" ~/projects/repoAvoid `sudo chown -R $USER ~` (the entire home directory). A recursive chown of all of ~ can clobber the intended ownership of files that are supposed to differ, such as ~/.gnupg, ~/.ssh socket/agent files, snap or cache directories owned by services, and mounted subdirectories. Target the exact subdirectory instead.
A "Permission denied" message can occasionally mask a disk-full or read-only condition:
# Check available space on the filesystem holding the current directory
df -h .
# See how that filesystem is mounted (look for 'ro' vs 'rw')
mount | grep "$(df --output=source . | tail -1)"If the disk is full, free space safely (review before deleting):
# Find large directories to investigate
du -h -d1 / 2>/dev/null | sort -h | tail -20
# Clear package manager cache if appropriate for your distro
sudo apt clean # Debian/Ubuntu
sudo dnf clean all # Fedora/RHEL (or: sudo yum clean all)If the filesystem is genuinely read-only and that is unintended, you can remount it read-write (understand why it was read-only first, as that may indicate disk errors):
sudo mount -o remount,rw /mountpointOn NFS or CIFS/SMB mounts, the server's export options and your mapped user/group control whether you can write:
mount | grep -E 'nfs|cifs'For NFS, the export must be read-write and your UID must be permitted by the server; remounting locally cannot grant access the server denies:
# Remount read-write (only works if the export allows it)
sudo mount -o remount,rw /nfs/shareFor CIFS/SMB, mount with your UID/GID so created files belong to you:
sudo mount -t cifs //server/share /mnt/share \
-o username=you,uid=$(id -u),gid=$(id -g)On a managed system, contact your administrator if you cannot change export or mount options.
### Do not run sudo git clone
You *can* run sudo git clone, but avoid it. It makes the whole repository owned by root, forces every later Git command to use sudo, and runs Git (and any clone-time hooks) as root, which is a security risk. Prefer creating the target directory and chowning it to your user first (see step 3). If a repo was already cloned as root, fix only that repo's ownership: sudo chown -R "$USER:$USER" /path/to/repo.
### macOS: System Integrity Protection
On macOS, system locations such as /, /System, and /usr (except /usr/local) are protected by System Integrity Protection, so writes there fail even with sudo. Clone into your home directory, /usr/local, or /opt instead:
git clone https://github.com/user/repo.git /usr/local/src/myrepo
git clone https://github.com/user/repo.git ~/Developer/myrepo### Docker volume permissions
When cloning into Docker volumes or bind mounts, the container's user often does not match the host UID, causing permission denied. Run the container with your UID/GID:
docker run --user $(id -u):$(id -g) -v "$(pwd)":/workspace myimage \
git clone https://github.com/user/repo.git /workspace/repoIf the mount is already root-owned, fix ownership of the mounted path (not the whole container filesystem) before cloning.
### SELinux
On RHEL/CentOS/Fedora with SELinux enforcing, a write can be blocked even when standard permissions look correct. Check for denials first:
sudo ausearch -m avc -ts recentTo confirm SELinux is the cause, you can briefly set it permissive for testing, then restore enforcing immediately afterward:
sudo setenforce 0 # temporary test only
# re-run your git clone
sudo setenforce 1 # restore enforcing right awayIf permissive mode fixes it, do not leave SELinux disabled. Generate and install a targeted policy, or relabel the directory with the correct context (often the real fix):
sudo ausearch -m avc -ts recent | audit2allow -M mypolicy
sudo semodule -i mypolicy.pp
# Often the cleaner fix is restoring the expected context:
sudo restorecon -Rv /path/to/target### Windows / WSL
Cloning onto the Windows filesystem from WSL (paths under /mnt/c) can hit permission and metadata issues. Prefer WSL's native filesystem:
cd ~
git clone https://github.com/user/repo.gitIf you must use /mnt/c, enable metadata in /etc/wsl.conf and restart WSL:
[automount]
options = "metadata,umask=22,fmask=11"### A convenience alias
Git has no built-in "default clone directory" setting, but a shell alias makes a standard location easy:
mkdir -p ~/repos
alias gcl='git -C ~/repos clone'ssh: Could not resolve hostname github.com: Name or service not known
How to fix 'ssh: Could not resolve hostname github.com: Name or service not known' in Git
error: insufficient permission for adding an object to repository database .git/objects
How to fix "insufficient permission for adding an object to repository database" in Git
Smudge error: Error downloading object: The requested URL returned error
How to fix Git LFS 'Smudge error: Error downloading object' error
fetch-pack: unexpected disconnect while reading sideband packet
How to fix 'unexpected disconnect while reading sideband packet' in Git
error: multi-pack-index verification failed
How to fix 'multi-pack-index verification failed' error in Git