Speeding Up Laravel Tests with tmpfs (MySQL in RAM)
If your Laravel test suite is painfully slow and does a lot of database work (multi-tenancy, migrations, seeding), the bottleneck is almost…
You're trying to switch branches and git yells at you:
git checkout feature-branch
error: Your local changes to the following files would be overwritten by checkout:
composer.lock
Please commit your changes or stash them before you switch branches.
Aborting
Here's how to fix it:
# First, clean up your current state
rm -rf vendor/
rm composer.lock
# Now you can switch branches
git checkout feature-branch
# And finally get your dependencies
composer install
This works because you're removing the conflicting files before trying to switch branches. The vendor directory and lock file from your current branch are gone, so git can freely switch to the other branch. Then Composer will set up everything fresh based on that branch's composer.json.
Save yourself some typing with this alias in your .bash_aliases or .zshrc:
alias fresh-composer='rm -rf vendor/ && rm composer.lock && composer install'
Then whenever you need to switch branches with different dependencies:
rm -rf vendor/ && rm composer.lock # Clear the way first
git checkout other-branch
fresh-composer
If you're using Laravel Sail, there's a catch: Sail lives in your vendor directory! When you delete vendor/, you can't use sail composer install anymore because Sail itself is gone. Here's how to handle it:
# Delete current state
rm -rf vendor/
rm composer.lock
# Get the lock file from the branch you're switching to
git checkout feature-branch composer.lock
# Run composer install via Docker directly
docker run --rm \
-u "$(id -u):$(id -g)" \
-v "$(pwd):/var/www/html" \
-w /var/www/html \
laravelsail/php83-composer:latest \
composer install --ignore-platform-reqs
Replace php83 in laravelsail/php83-composer:latest with your PHP version:
laravelsail/php74-composer:latestlaravelsail/php80-composer:latestlaravelsail/php81-composer:latestlaravelsail/php82-composer:latestlaravelsail/php83-composer:latestAfter this runs, Sail will be back in your vendor directory and you can use it normally again.
For Sail projects, you might want a more specific alias:
alias fresh-sail-composer='rm -rf vendor/ && rm composer.lock && docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/var/www/html" -w /var/www/html laravelsail/php83-composer:latest composer install --ignore-platform-reqs'
Now you can switch branches cleanly regardless of whether you're using standard PHP or Laravel Sail:
rm -rf vendor/ && rm composer.lock # Clear the way first
git checkout other-branch
# For standard PHP projects:
fresh-composer
# For Sail projects:
fresh-sail-composer
Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.
Take a look at vroni.com