How to fix fatal: destination path already exists and is not an empty directory in Git

GitBEGINNERLOWUpdated Jul 7, 2026· 1,557 views

Fix Git's "destination path already exists and is not an empty directory" clone error by removing or renaming the existing folder, or cloning into a new path.

Quick fix

Fixes fatal: destination path already exists and is not an empty directory

ls -la repo/
  1. Check what exists in the target directory
  2. Remove the existing directory (if safe)
  3. Clone to a different directory name
  4. Use git pull if you already have the repository
git — error
ls -la repo/
fatal: destination path already exists and is not an empty directory

What this error means

When you run `git clone`, Git creates a new directory with the repository's name (or the name you specify) and downloads all repository contents into it. If a directory with that name already exists and contains any files—even hidden files like `.DS_Store` on macOS or a previous `.git` folder—Git will abort the clone operation with this fatal error. This is a safety feature. Git intentionally refuses to clone into a non-empty directory because doing so could overwrite or corrupt existing files. There is no `--force` flag to bypass this restriction; you must resolve the conflict manually by either removing the existing directory, choosing a different destination, or using an alternative approach to fetch the repository.

Typical symptoms

  • Running git clone fails immediately with a fatal error
  • The error message includes the exact directory name that already exists
  • The clone operation creates no new files
  • Repeated clone attempts produce the same error
  • CI/CD pipelines fail during the checkout or clone step

Common causes

  1. A previous clone attempt was interrupted and left a partial directory
  2. A directory with the same name as the repository already exists from previous work
  3. Hidden files like .DS_Store (macOS) or Thumbs.db (Windows) exist in an otherwise empty directory
  4. A previous .git directory remains from an earlier initialization
  5. The current directory (.) was specified as the destination but is not empty
  6. CI/CD build cache retained the directory from a previous run

How to fix "fatal: destination path already exists and is not an empty directory"

1Check what exists in the target directory

Before taking action, inspect what's in the directory causing the conflict:

bash
ls -la repo/

This shows all files including hidden ones. You may find:
- A .git folder from a previous clone
- Hidden system files like .DS_Store
- Actual project files you need to preserve

2Remove the existing directory (if safe)

If the directory contains nothing important, remove it and clone again:

bash
rm -rf repo
git clone https://github.com/user/repo.git

On Windows:

cmd
rmdir /s /q repo
git clone https://github.com/user/repo.git

Warning: This permanently deletes the directory and all its contents. Make sure you don't need any files inside.

3Clone to a different directory name

If you want to keep the existing directory, clone into a new location by specifying a different name:

bash
git clone https://github.com/user/repo.git repo-new

You can name it anything you want. This is often the safest approach when you're unsure about the existing directory's contents.

4Use git pull if you already have the repository

If the existing directory is actually a Git repository you cloned before, you don't need to clone again—just update it:

bash
cd repo
git pull origin main

Check if it's a valid repository first:

bash
cd repo
git status

If this works, you already have the repo and just need to pull updates.

5Initialize and fetch into existing directory

If you need to clone into a directory that has files you want to keep (like configuration files), use init and fetch instead:

bash
cd existing-directory
git init
git remote add origin https://github.com/user/repo.git
git fetch origin
git checkout main -f

Note: The -f flag forces checkout and may overwrite conflicting files. Review what's in the directory first.

6Fix CI/CD pipeline issues

In CI/CD environments, this error often occurs when the workspace isn't cleaned between runs. Solutions vary by platform:

GitHub Actions: The checkout action handles this automatically, but ensure you're using actions/checkout@v4

GitLab CI: Add cleanup or use GIT_STRATEGY: clone with GIT_CLEAN_FLAGS: -ffdx

Jenkins: Enable 'Clean before checkout' in your pipeline settings

Generic fix: Add a cleanup step before clone:

bash
rm -rf ./repo || true
git clone https://github.com/user/repo.git

Advanced notes

Cloning into the current directory: If you want to clone directly into your current directory (represented by .), it must be completely empty—no files, no hidden files, nothing. The command git clone <url> . will fail if any file exists.

Why no --force flag?: Unlike some Git operations, git clone has no force option to overwrite existing directories. This is by design to prevent catastrophic data loss. The clone operation is meant for fresh checkouts only.

Sparse checkout alternative: If you only need part of a repository and want more control over what gets written, consider using sparse checkout:

bash
git clone --filter=blob:none --sparse https://github.com/user/repo.git
cd repo
git sparse-checkout set path/to/directory

Worktrees: If you need multiple working copies of the same repository, use git worktree instead of cloning multiple times:

bash
git worktree add ../repo-feature feature-branch

Frequently asked questions

What does "fatal: destination path already exists and is not an empty directory" mean?
When you run git clone, Git creates a new directory with the repository's name (or the name you specify) and downloads all repository contents into it. git folder—Git will abort the clone operation with this fatal error. This is a safety feature.
How do I fix "fatal: destination path already exists and is not an empty directory"?
Fix Git's "destination path already exists and is not an empty directory" clone error by removing or renaming the existing folder, or cloning into a new path.
What causes "fatal: destination path already exists and is not an empty directory"?
A previous clone attempt was interrupted and left a partial directory A directory with the same name as the repository already exists from previous work Hidden files like .DS_Store (macOS) or Thumbs.db (Windows) exist in an otherwise empty directory
Is the "fatal: destination path already exists and is not an empty directory" error serious?
It is a low-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading