Last Updated: October 30, 2021
·
5.007K
· vitorbal

The most awesome git alias on the planet

Nowadays, everyone has their own set of favorite git alias commands that you can't live without anymore. These are some of my favorite ones:

The Usual Suspects

b = branch
f = fetch
co = checkout
ci = commit
cp = cherry-pick
com = checkout master

These are the bread and butter of the arsenal, and every gitter should have some variation of these aliases. They spare you so much time it's insane. The only downside I can imagine is that when you are gitting on someone else's computer you look like a total idiot because you will keep writing git commands that won't work.
I also like to add an alias g="git" on my .bash_profile. Yeah that's right, I'm that lazy.

Make it Pretty

lp = log --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative

This one is just pure gold, makes your log command look actually
- gasp - pretty!
Some people also like to include -graph to the package to show the graphical representation of your branches.

In the Zone

You're now on your way to becoming a git superstar. You need something to make your gitting experience even more unique. Well, ladies and gentleman, I present to you, my all-time favorite git alias and most certainly the most awesome git alias on the planet:

mav = !afplay ~/Music/Danger\\ Zone.mp3 & LASTPID=$! \ngit rebase -i $1 \nkill -9 $LASTPID\n true

I got this one from a stackoverflow answer some time ago. Look around there if you want some more git alias goodyness.

Anyway, turns out someone in the comments said you could also stop the music after rebasing if you kept a hold of its pid. So I decided to try it out and that's what I came up with.

Basically, three things are happening. First,we call afplay to start the song on the background (with &). Then, we save its process id to a variable called LASTPID, start our rebase, and send a kill command to that pid after that.

Note that the kill will only happen after you finish the rebase, since that command will only run after the rebase process ends.

EDIT: Thank you kmerz@ and mhauser@ for the \n true tip

1 Response
Add your response

Wouldn't you want to be the exit code of that alias to be the exit code of the git rebase rather than just "true"?

over 1 year ago ·