This error occurs when Git cannot create the target directory for a clone operation due to filesystem permissions. The fix typically involves cloning to a directory you own, adjusting permissions on the parent directory, or using sudo with proper ownership correction.
When you run `git clone`, Git attempts to create a new directory (the "work tree") at your specified or default location. This fatal error appears when your user account doesn't have write permission to the parent directory where Git is trying to create the repository folder. The error message tells you exactly which directory Git tried to create (in quotes) and that the operating system denied the operation. This is a filesystem-level permission error, not a Git-specific problem. 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 don't have write access to 3. **Shared servers** - Working on multi-user systems where your home directory is misconfigured 4. **Network-mounted filesystems** - NFS, CIFS, or other mounts with restrictive permissions 5. **Read-only filesystems** - USB drives mounted as read-only or disk full conditions
First, verify where you're trying to clone and whether you have write permissions:
pwd
ls -la .Look at the output - if the directory is owned by root or another user, that's your problem:
drwxr-xr-x 5 root root 4096 Jan 15 10:00 .The r-x for others (the last three characters) means you can read and execute but not write.
The simplest solution is to clone to a directory you own:
cd ~
git clone https://github.com/username/repo.gitOr specify a full path within your home directory:
git clone https://github.com/username/repo.git ~/projects/repoYou can also create a dedicated projects directory:
mkdir -p ~/projects
cd ~/projects
git clone https://github.com/username/repo.gitIf you need to clone to a specific location outside your home directory, create it first with appropriate ownership:
# Create the directory with sudo
sudo mkdir -p /opt/projects
# Change ownership to your user
sudo chown $USER:$USER /opt/projects
# Now clone works without sudo
git clone https://github.com/username/repo.git /opt/projects/repoImportant: Don't run git clone itself with sudo - this creates a repository owned by root, causing permission issues later.
If your home directory ownership was accidentally changed, fix it:
# Check home directory ownership
ls -la ~
# If owned by root, fix it
sudo chown -R $USER:$USER ~This can happen if you've run commands like sudo git clone or sudo npm install in your home directory.
Warning: Be careful with recursive chown in ~ if you have special files or directories with intentionally different ownership.
Permission denied errors can sometimes mask disk-full conditions:
# Check available disk space
df -h .
# Check if filesystem is read-only
mount | grep "$(df . | tail -1 | awk '{print $1}')"If the disk is full:
# Find large files
du -sh /* 2>/dev/null | sort -h | tail -20
# Clear package manager cache
sudo apt clean # Debian/Ubuntu
sudo yum clean all # RHEL/CentOSIf the filesystem is mounted read-only (ro), remount it:
sudo mount -o remount,rw /mountpointFor NFS or CIFS mounted directories, check mount options:
mount | grep nfs
mount | grep cifsCommon fixes for NFS:
# Remount with proper options (edit /etc/fstab for persistence)
sudo mount -o remount,rw,user /nfs/shareFor CIFS/SMB shares, ensure proper credentials and permissions:
# Mount with your user/group IDs
sudo mount -t cifs //server/share /mnt/share -o username=you,uid=$(id -u),gid=$(id -g)Contact your system administrator if you're on a managed system and can't modify mount options.
### Using sudo git clone (and why you shouldn't)
While you *can* run sudo git clone, this creates several problems:
1. The cloned repository will be owned by root
2. All subsequent Git operations require sudo
3. It's a security risk to run Git as root
If you must clone as root, immediately fix ownership:
sudo git clone https://github.com/user/repo.git /opt/myrepo
sudo chown -R $USER:$USER /opt/myrepo### macOS Specific Issues
On macOS, certain directories like / are protected by System Integrity Protection (SIP). Even with sudo, you cannot write there. Use /usr/local, /opt, or your home directory instead.
# This will fail even with sudo on macOS
sudo git clone repo /System/something # SIP blocks this
# Use these instead
git clone repo /usr/local/src/myrepo
git clone repo ~/Developer/myrepo### Docker Volume Permissions
When cloning into Docker volumes or bind mounts, permission issues are common:
# Run container with your user ID
docker run --user $(id -u):$(id -g) -v $(pwd):/workspace myimage
# Or fix permissions inside container
docker run -v $(pwd):/workspace myimage bash -c "
chown -R $(id -u):$(id -g) /workspace
git clone https://github.com/user/repo.git /workspace/repo
"### SELinux Considerations
On RHEL/CentOS/Fedora with SELinux enabled, check for denials:
# Check for recent SELinux denials
sudo ausearch -m avc -ts recent
# Temporarily set SELinux to permissive to test
sudo setenforce 0
# If it works in permissive mode, create a policy
sudo audit2allow -a -M mypolicy
sudo semodule -i mypolicy.pp### Windows/WSL Considerations
When working in WSL with Windows filesystem paths:
# Windows paths in WSL may have permission issues
# Prefer cloning to WSL's native filesystem
cd ~
git clone https://github.com/user/repo.git
# If you must use /mnt/c, ensure proper permissions in /etc/wsl.conf:
# [automount]
# options = "metadata,umask=22,fmask=11"### Git Config for Safer Cloning
You can configure Git to always clone to a specific directory:
# Create a default clone location
mkdir -p ~/repos
git config --global clone.defaultDirectory ~/repos
# Or use a shell alias
alias gcl='cd ~/repos && git clone'warning: BOM detected in file, this may cause issues
UTF-8 Byte Order Mark (BOM) detected in file
fatal: Server does not support --shallow-exclude
Server does not support --shallow-exclude
warning: filtering out blobs larger than limit
Git partial clone filtering large blobs warning
fatal: Server does not support --shallow-since
Server does not support --shallow-since in Git
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server