← Articles
Dark theme

TIL: How to checkout to "previous" branch

☕ 1 min read

Git is the kind of awesome tool that keeps giving. Ok, this feature is not as impressive as git worktree or the powerful reflog, but it’s very handy.

Say you’re on a branch. You checkout to master temporarily. Then, you want to come back to your branch. Wait… what’s the name of your branch again?

Turns out, you can just ask git to go back to the previous branch you were on with git checkout -.

It works like cd -: it checkouts the previous branch and if you run it twice, you’ll end up on the same branch you’re now.

Demo of the command

And you, do you have any git trick? 😜

Published 2 Dec 2019Discuss this article on Twitter

Did you know?

I’m the author of understandlegacycode.com and I’m building an interactive course to teach you to refactor any JavaScript application: refactoringjavascript.dev.

Every week, I share practical tips to help people work with Legacy Code.


I write about VS Code, web development and life in general.