~1 min read

Tags

Back in August, I wrote about making an alias for finding the five most recent branches I have checked out by filtering out git reflog entries.

Here’s how the output looks like for the alias:

➜  sdk_sandbox git:(feature/app-shortcuts) βœ— grefb  
1 - main
2 - feature/clickable-spans
3 - main
4 - task/update-gradle
5 - task/update-to-mdc

The alias has been really useful and I have been using it a lot, but the command to actually switch branches is a bit difficult to type.

➜  sdk_sandbox git:(feature/app-shortcuts) βœ— gco @{-3}
Switched to branch 'main'
Your branch is up to date with 'origin/main'.

So today I added a new alias that will put in the command for me:

alias gcobr='() { gco @{-$1} ;}'

This means I can just enter the index of the branch I want to go back to without having to worry about the syntax :tada: :

➜  sdk_sandbox git:(feature/app-shortcuts) βœ— gcobr 3
Switched to branch 'main'
Your branch is up to date with 'origin/main'.