DEV Community

Clive Da
Clive Da

Posted on

a nasty git alias hack

a nasty git bash alias hack

DO NOT DO THIS IN THE REAL WORLD

create a file ~/.bash_aliases

$ cat ~/.bash_aliases 
alias ga="git add ."
alias gc='git commit -m "autocommit"'
alias gd="git diff"
alias gp="git push"
alias gs="git status"

now you can add commit and push with 6 chars

$ ga
$ gc
$ gp

WARNING

FOR RAPID PROTOTYPING USE ONLY
this is a sackable offence in many outfits as it creates meaningless commit messages 😁

Top comments (11)

Collapse
 
mousetail profile image
Maurits van Riezen

If you replace

alias gc='git commit -m "autocommit"'

with just

alias gc='git commit -m'

You could do

gc "Fixed something"

and it would be a timezaver for real projects too

Collapse
 
osde8info profile image
Clive Da

you havent met my mgr have you ? so thanks but "fixed something" would be unacceptable :) it needs to have the JIRA num in it at least

Collapse
 
daniel13rady profile image
Daniel Brady • Edited

πŸ˜† πŸ‘ Good manager you've got there, Clive. I don't think mine has ever even seen my commit messages, let alone cares about them.

But I think Maurits' point was more that if you don't include a default commit message in the alias, you can save yourself some typing (by shortening git commit -m to gc) while still requiring a message from yourself on the command line.

I started using Zsh as a default shell instead of Bash a few years ago (no real reason besides curiosity) along with the Oh My Zsh framework, and that framework adds a metric shit-ton of git aliases along those lines.

I don't use them these days as I prefer interacting with git directly from my editor, but I tried them out in the beginning and they were fun to use for awhile.

Thread Thread
 
osde8info profile image
Clive Da

yes your right he is NOT actually recommending the same text for every commit if you read carefully sorry my mistake

Thread Thread
 
osde8info profile image
Clive Da

and i certainly hope your mgr isnt reading DEVTO ! :)

Collapse
 
nombrekeff profile image
Keff

Why do you recommend not to use in the real world? I don't think there is any issues with this...

Collapse
 
osde8info profile image
Clive Da

have a quiet chat with your mgr :)

Collapse
 
nombrekeff profile image
Keff

Sorry for my ignorance, but what is "mgr"? Manager?

Thread Thread
 
osde8info profile image
Clive Da

sorry mgr is shorthand for manager most dev mgrs require you to at least put the jira number in any git comment :)

Thread Thread
 
nombrekeff profile image
Keff

Ahh ok, thanks, I assumed so, but was not sure :P

Collapse
 
osde8info profile image
Clive Da

nice one ! i will replace my alias list with that much more comprehensive one !