Find and Switch to a Branch by Partial Name
Search across local and remote branches for a pattern like "feat/mu" and jump onto it.
When to use
You remember part of a branch name (for example, feat/mu) but need a quick way to locate it and resume work.
Pre-flight
- Your repository already has the branch in question locally or on a remote such as
origin. - You have permission to fetch from the remote so the branch list is current.
Steps
-
Refresh branch information so you do not miss recently pushed work.
git fetch --all --prune -
Search for branches whose names include your fragment. Wildcards let you match patterns such as
*feat/mu*.git branch --all --list '*feat/mu*' -
Switch to the branch once you spot the exact name.
# Branch already exists locally git switch feat/mu # Branch only on the remote (creates local tracking branch) git switch --track origin/feat/mu
Verification
git statusreports "On branch feat/mu" and shows the working tree state.git branch --show-currentechoesfeat/mu.
Follow-up
- Run
git pullto grab any commits pushed after you last worked on the branch. - Use
git switch -later if you need to hop back to the previous branch quickly.
Concept refresher
Need a deeper comparison of git switch, git checkout, and git restore? Read Choose Between git switch, git checkout, and git restore.