Rizwan Rizwan
HOME SERVICES CASE STUDIES BLOG ABOUT $100 USD FREE Consultation Call →
LARAVEL

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:

Rizwan Rizwan May 27, 2025 5 min read
Fixing “Project directory is not empty.” Error in Laravel (Without Nuking Your Git Repo)

Table of Contents

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 made this mistake myself dozens of times:

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

And... 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. And if you're also configuring your server, see my LEMP Installation guide

Rizwan

About Rizwan

Full-stack developer and technical leader with 13+ years building scalable web applications. I help agencies and startups ship faster through strategic guidance and hands-on development.

MORE INSIGHTS

Keep reading for more development wisdom.

DevOps

How to Set Up a Secure Deploy User for GitHub Actions (And Why You Should Never Use Root)

Avoid root in Laravel CI/CD. Here’s how to create a secure "deploy" user for GitHub Actions, with exact commands and a full checklist.

Rizwan Rizwan July 13, 2025 5 min read
Laravel

How to Fix Email Verification in FilamentPHP 3.X

If you're dealing with a 403 error when signing up on your FilamentPHP application, don't worry. There's a simple fix to get your email verification working

Rizwan Rizwan May 27, 2025 5 min read

HOW I CAN HELP YOU

I work with founders, agencies, and developers who need that extra push to get projects live. Whether it's fixing a stubborn bug, steering your tech strategy, or building full apps with my team. You don't have to do it alone

GET UNSTUCK

60-minute call to debug your specific problem. Stop spinning your wheels.

$249
BOOK NOW →

FRACTIONAL CTO

Ongoing strategic guidance to prevent disasters like this.

$2k-7k/mo
LEARN MORE →

CUSTOM DEV

Full project rebuild with our expert team. Done right the first time.

Custom
GET QUOTE →