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
!