Jump back to the last branch with git switch -
Bouncing between a feature branch and main? - means "the branch I was just on," so you never type its name.
- Run
git switch main(or any other branch) to leave your feature branch. - Run
git switch -to go straight back. - Run
git switch -again to flip back the other way.
Tip: - is short for @{-1}. Use git switch @{-2} to go back two branches.
Try it now: In any repo with two branches, switch to one, then run
git switch - twice and watch git branch change.Next crumbs
- 💻 Terminal & gitJump back with cd -Toggle between your last two directories, like Alt+Tab for folders.
- 💻 Terminal & gitPark unfinished work with git stashNeed to switch branches but you're mid-change? Stash it, switch, and bring it back later.
- 💻 Terminal & gitSearch your shell history with Ctrl+RStop pressing the up arrow 40 times. Type any part of an old command and it appears.