The macOS hostname is split across three scutil keys, and the one that drives your shell prompt isn't the only one you usually want to set:
HostName— the network hostname shown in your shell promptComputerName— what System Settings → General → Sharing and Finder showLocalHostName— the Bonjour.localname used by AirDrop and LAN SSH
Set all three at once so they don't drift:
1sudo scutil --set ComputerName "mbp-andreas"
2sudo scutil --set LocalHostName "mbp-andreas"
3sudo scutil --set HostName "mbp-andreas"
4dscacheutil -flushcacheLocalHostName only accepts letters, digits, and hyphens — no spaces or punctuation.
Already-open shells keep the old prompt until you exec $SHELL or open a new tab. No reboot needed.
Confirm with:
1scutil --get HostName