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 :
β sdk_sandbox git:(feature/app-shortcuts) β gcobr 3
Switched to branch 'main'
Your branch is up to date with 'origin/main'.