Wait, why is my feature breaking? Oh no… I forgot to run
php artisan migrate
after pulling!
If you're part of a Laravel development team, this scenario might sound familiar. It happened to me more than once, and maybe it’s happening to you too. In this post, I’ll walk you through a simple, local-only solution to automatically run Laravel migrations right after you run git pull
. No CI/CD, no shell scripts — just a smart git
alias.
🧩 The Problem — A Common Developer Story
In our team, we often push updates that include database migrations. For example:
- I work on a feature and create a new migration.
- After testing, I push it to GitHub.
- My teammate pulls the latest code for code review.
- But — they forget to run
php artisan migrate
😵💫. - Boom. The app crashes because the schema isn’t up to date.
This isn’t anyone’s fault — it’s easy to forget when you’re multitasking or context-switching. That’s why I wanted a local automation that ensures every time I do a git pull
, it also runs migrations and refreshes Laravel’s config cache.
So here's how we fixed it... 👇
⚙️ The Solution — Custom Git Alias with Migration Command
We're going to define a custom git
alias that:
- Pulls the latest changes
- Installs dependencies
- Runs the Laravel migrations
- Clears and rebuilds the config cache
✅ Final Alias Command:
alias gpm='git pull && composer install && php artisan migrate --force && php artisan config:cache'
✅ Simpler Version (without Composer install/cache):
[alias]
gpm = "!git pull && php artisan migrate && php artisan cache:clear"
You can choose based on your needs.
🧑💻 Step-by-Step Setup
Step 1: Set VS Code as Your Default Git Editor (Optional)
git config --global core.editor "code --wait"
This makes editing the Git config easier.
Step 2: Open Your Global Git Config
git config --global --edit
This opens the Git configuration file. You’ll be adding a custom alias.
Step 3: Add the Alias
Inside the opened file, scroll to the bottom and add:
[alias]
gpm = "!git pull && php artisan migrate && php artisan cache:clear"
Or for a more complete workflow:
[alias]
gpm = "!git pull && composer install && php artisan migrate --force && php artisan config:cache"
🔐
--force
is important in Laravel when runningmigrate
from a script/alias to bypass confirmation prompts.
Step 4: Save and Close
Save the file and close the editor.
Step 5: Use Your New Command
Now whenever you want to pull the latest changes and run migrations:
git gpm
✅ It will:
- Pull the latest changes
- Run Laravel migrations
- Clear the cache
No more forgetting php artisan migrate
!
Top comments (0)