Fixing “Project directory is not empty.” Error in Laravel (Without Nuking Your Git Repo)

If you’ve ever set up a fresh Laravel project after initializing your GitHub repo, you’ve probably seen this annoying error: […]

If you’ve ever set up a fresh Laravel project after initializing your GitHub repo, you’ve probably seen this annoying error:

[InvalidArgumentException]  
Project directory is not empty.

It’s Composer’s way of saying:

“Hey, I’m not touching your .git folder or whatever else you’ve got lying around.”

Which is fair. But also annoying when you just want to get Laravel running without wiping your Git setup.

Why This Happens (Real World)

Here’s a common scenario — I’ve done this myself dozens of times:

  1. Create a new repo on GitHub
  2. Clone it locally: git clone [email protected]:your-username/project-name.git cd project-name
  3. Try to install Laravel directly in this directory: composer create-project laravel/laravel .

Boom. Error.

This happens because the directory already has .git and possibly a README.md or .gitignore. Composer won’t overwrite that.


The Clean Workaround (No Deleting, No Force)

Here’s the approach I use every time now. It avoids the error and keeps your Git history intact.

Step 1: Install Laravel into a Temp Directory

mkdir -p /tmp/laravel-temp  
composer create-project laravel/laravel /tmp/laravel-temp

This creates a fresh Laravel install away from your current Git repo.

Step 2: Move Laravel into Your Project Folder

While inside your repo folder:

Option A (Safe Copy)

cp -r /tmp/laravel-temp/. ./
rm -rf /tmp/laravel-temp

Option B (Skip .git just in case)

rsync -av --progress /tmp/laravel-temp/ ./ --exclude .git
rm -rf /tmp/laravel-temp

That’s it. Your Laravel app is now inside your Git repo, ready to push.


Bonus: Push to GitHub

After setup, you can commit the Laravel boilerplate and push to GitHub like usual:

git add .  
git commit -m "Initial Laravel setup"  
git push origin main

This is one of those Laravel quirks that keeps biting even experienced devs. The workaround isn’t complicated — but it’s easy to forget. Hopefully this saved you a few minutes (or hours) of frustration.

If you’re doing serious Laravel work, make sure to check out how I fixed email verification in FilamentPHP — especially useful if you’re building dashboards or admin panels.