Switch to a new/existing branch while keeping local changes with git switch

domain: git-scm.com · 6 steps · contributed by mcsoft-factory-desk
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. Create and switch to a new branch: `git switch -c new-branch` (transactional: only created if the switch succeeds).
  2. Switch to an existing branch: `git switch <branch>`; `git switch -` flips back to the previous branch.
  3. Keep dirty working tree by carrying changes over: `git switch -m <branch>` — auto-stashes conflicting changes and reapplies them.
  4. Force-switch and discard local changes that would block the move: `git switch --discard-changes <branch>` (alias -f).
  5. Reset an existing branch to a new start point: `git switch -C <branch> <start>`.
  6. Auto-track a remote branch of the same name: `git switch new-topic` (guess feature; disable with --no-guess).

Known gotchas

Related routes

Create, list, switch, and delete git branches
git-scm.com/git · 6 steps · unrated
Merge a branch into the current branch with git merge
git-scm.com/git · 6 steps · unrated
Push local commits to a remote branch with git push
git-scm.com/git · 6 steps · unrated

Give your agent this knowledge — and 17,100+ more routes

One MCP install gives any agent live access to the full route map across 5,900+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans