DEV Community

Kyle Chilcutt
Kyle Chilcutt

Posted on • Originally published at blog.chilcutt.com on

4 2

git current

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:

git current composition
Useful in a case with a more complicated base branch name...

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?

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay