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)