The Situation
You run git clone, hit Enter, and immediately get slapped with:
fatal: destination path 'project-name' already exists and is not an empty directory.
Maybe you cloned this repo before and forgot. Maybe a previous clone died halfway. Maybe a teammate already put something in that folder. Either way, Git refuses to overwrite it โ and you need this working now.
Why This Happens
Git won't clone into a directory that already exists and has files in it. That's intentional โ it's protecting you from overwriting work you might care about. The directory could contain:
- A previous (possibly incomplete) clone of the same repo
- A partially extracted archive or scaffold
- Unrelated files that ended up there by mistake
- A completely different Git repo
Figure out which case you're in before doing anything โ the fix is different for each.
Step 1 โ Inspect What Is Already There
# See what's inside
ls -la project-name/
# Check if it's already a git repo
ls -la project-name/.git/
A .git/ folder means you already have a clone โ complete, broken, or outdated. No .git/ means it's just a plain directory sitting in the way.
Quick Fix A โ Delete and Re-clone (Cleanest)
Nothing worth keeping in that folder? Wipe it and start fresh:
# Linux / macOS
rm -rf project-name/
git clone https://github.com/org/project-name.git
# Windows PowerShell
Remove-Item -Recurse -Force project-name
git clone https://github.com/org/project-name.git
# Windows CMD
rd /s /q project-name
git clone https://github.com/org/project-name.git
Confirm it worked:
cd project-name
git status
# Should show: On branch main, nothing to commit
Quick Fix B โ Clone Into a Different Directory
Don't want to delete the existing folder? Tell Git to use a different target name instead:
git clone https://github.com/org/project-name.git project-name-fresh
Or create a versioned copy alongside it:
mkdir project-name-v2 && git clone https://github.com/org/project-name.git project-name-v2
This is the zero-risk option โ nothing gets deleted or overwritten.
Quick Fix C โ The Directory Is Already a Clone (Fetch + Reset)
Got a .git/ folder? That directory is already a Git repo. Don't delete it โ just update it:
cd project-name
# Verify it points to the right remote
git remote -v
# Pull latest changes
git fetch --all
git reset --hard origin/main
# Or for a clean slate that exactly matches the remote
git fetch origin
git checkout main
git reset --hard origin/main
git clean -fd
One warning: git clean -fd permanently deletes untracked files and directories. Double-check there's nothing unsaved before running that line.
Quick Fix D โ Initialize and Pull (If No .git Exists)
Got source files in the folder but no Git history? Skip cloning entirely โ initialize a repo in place and pull from the remote:
cd project-name
git init
git remote add origin https://github.com/org/project-name.git
git fetch origin
git reset --hard origin/main
Your existing files stay put while Git downloads the full history. Just know that git reset --hard will overwrite local changes with whatever is on the remote branch โ so save anything you want to keep first.
Permanent Fix โ Use a Workspace Directory
This error hits hardest on CI/CD systems and on dev machines juggling multiple repos. The simplest habit that prevents it: always clone under a dedicated workspace folder.
# Instead of:
git clone https://github.com/org/project-name.git
# Do this:
mkdir -p ~/workspace
cd ~/workspace
git clone https://github.com/org/project-name.git
On CI/CD, add a cleanup step before the clone:
# GitHub Actions example
- name: Clean workspace
run: rm -rf ${{ github.workspace }}/project-name
- name: Clone repo
run: git clone $REPO_URL
Even simpler โ use the built-in actions/checkout action. It handles stale directories automatically.
On Jenkins, enable Wipe out repository & force clone in the SCM settings, or add a shell step:
rm -rf ${WORKSPACE}/project-name || true
git clone ${REPO_URL} project-name
Verify the Fix
cd project-name
# Confirm it's a valid repo
git status
# Confirm remote is correct
git remote -v
# Check the last few commits landed correctly
git log --oneline -5
A clean clone looks like this:
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
That output means you're done. Untracked files or unexpected modifications in git status? Investigate before committing โ something got left behind.
Decision Cheatsheet
- Directory has nothing important โ delete it, re-clone
- Already a Git repo pointing to same remote โ fetch + reset
- Want to keep existing files โ clone into a different folder
- Has source files but no .git/ โ git init + remote add + fetch + reset
- Keeps happening in CI โ add cleanup step before clone

