Know When Your Branch Is Stale with Starship
If you’re using Starship, your shell prompt already tells you what branch you’re on. With one addition to your config, it can also tell you when that branch needs a rebase. Add this to ~/.config/starship.toml:
[custom.behind_main]
description = "Show commits behind origin/main"
command = "git rev-list --count HEAD..origin/main 2>/dev/null"
when = "git rev-parse --git-dir > /dev/null 2>&1 && [ $(git rev-list --count HEAD..origin/main 2>/dev/null) -gt 0 ]"
symbol = "↓"
style = "yellow bold"
format = "[$symbol$output behind main]($style) "
Now when your branch is behind, you’ll see ↓3 behind main in yellow in your prompt before you push. One thing to keep in mind: the count is only as fresh as your last git fetch.