As an avid vim
user, I have a weird aversion to ever using the mouse/trackpad to do anything–especially while at the command line. I noticed that one common thing for me to do was to run git branch or git status to see what branch I was on in order to use the branch name in another command. I didn’t like that.
tl;dr create a git alias for seeing your current branch:
$ git config alias.current "rev-parse --abbrev-ref HEAD"
$ git current # displays the current branch
The aliased command prints the current branch that you’re on to STDOUT
:
Once we have the alias created, we can do this even more simply:
The real beauty of the command is when you use it to compose another shell command. Let’s say I’m about to take on a few complicated and potentially dangerous operations and I want to create a backup branch because I don’t like spelunking the ref list if I can avoid it. I can easily create a backup branch based on the same name now:
Or if I realize I’ve gone down the wrong path and need to start over:
Being lazy sometimes sparks some cool ideas for minor tips/tricks/hacks that just make work more enjoyable. What are your favorites?
Top comments (0)