A Git Tip on

How to toggle between current & previous branch| GIT

Code hacks will save a lot of our developing time

Blackode
· 1 min read
Icons are the property of Git

Being a developer, we used to checkout the branches to and forth very often. It kills a lot of our time.

Git provides the following command to checkout the previous branch.

git checkout @{-N} ex..git checkout @{-1}

Where N — step count of the branches to move back on the checkout history.

Consider your project has following branch hierarchy and your current branch is features.

master → develop → features

So, just by typing git checkout @{-1} will take you to the develop branch.

Though it is handy, it is expensive in typing.

Let’s make it more simple and less typing.

git checkout -

is an alias for git checkout @{-1} .

Let’s make this more handy by creating some useful and meaningful aliases to save keystrokes.

alias bp='git checkout -' #bp -> branch-previous alias gco-='git checkout -' #gco- -> git check out - 

Check out the video

Happy Coding !!

blackode

Coding, thoughts, and ideas.

Blackode

Written by

Blackode

Wrong CODE takes U to the right BUG 🐞 coding, thoughts & ideas

blackode

blackode

Coding, thoughts, and ideas.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade