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

Should I Add Images to My Git Repository?

To commit or not commit. A list of reasons and resources to support your decision.

Sep 01, 2022

3 Ways to Add an Image to GitHub README

Images often come in handy alongside documentation. Here are a few methods for adding them to your README and other markdown files.

Jan 30, 2021

Backup Gitlab Data and Repositories to Amazon S3

Make sure you don't lose all that precious GitLab data by backing regularly and syncing with an Amazon S3 bucket.

Dec 11, 2014