Home

Git Checkout Previous Branch

Checkout the previous git branch without needing to remember or type the name.

If you want to checkout the branch you were previously working on, run this command:

git checkout -

It’s magic! You don’t have to remember or type the branch you were just on.

Example Git Merge Flow

Consider if I’m on a feature branch and I want to check out and update the main branch and merge changes into my feature branch. I can do this:

$ git checkout feature-branch

$ git checkout main

$ git pull origin main

$ git checkout -
# Now we're back on feature-branch, but let's check ...

$ git branch
* feature-branch
main

$ git merge main

(Technically, there’s a more efficient way to do this.) But the point is that I didn’t have to type “feature-branch” again. Instead, I changed back into the feature-branch branch automatically by running git checkout -.

Magic! 🪄

Let's Connect

Keep Reading

Delete Entire Word in Terminal and iTerm2

Ever find yourself holding down the Delete key on the command line? Here's a way to work faster.

Feb 08, 2021

Free Alternatives to GitHub for Private Git Hosting

GitHub is super awesome, until you have to start paying for it. Check out two feature-full and FREE alternatives.

Jan 08, 2015

Pro Tip: Use “1.” for Every Ordered List Item when Writing Markdown

A quick tip for making ordered lists in markdown easier to write.

May 31, 2022