DEV Community

Cover image for My Git Aliases

My Git Aliases

Nick Taylor on August 26, 2018

Alright, so @philnash roped me into this one. This post’s birth comes from a gist which is essentially a copy paste of my git aliases. I’m going ...
Collapse
 
rhymes profile image
rhymes • Edited

Nice list you have.

This is mine:

➜  ~ git alias
alias = config --get-regexp "alias.*"
append = commit --amend --no-edit
cached = diff --cached
ci = commit
co = checkout
find-change = name-rev
find-change-branch = branch --contains
hist = log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short
last = log -1 HEAD
log = log --full-history
lol = log --all --oneline --graph --decorate
ls = ls-files
merge = merge --no-ff
new = ls-files --others --exclude-standard
out = cherry -v
prune-remotes = remote prune origin
pull = pull --rebase
quick-stats = ! /usr/local/bin/git-quick-stats
release-tag = !git tag release-`date -u "+%Y%m%d%H%M"`
st = status -sb
standup = standup -d 8 -D iso
today = log --stat --since='1 Day Ago' --graph --pretty=oneline --abbrev-commit --date=relative
undo = reset HEAD^
unstage = reset HEAD --
who = shortlog -s

I don't use bisect or rebase that much so I don't have shortcuts. I use git out a lot to see what's going up to the origin. I've aliased merge to merge --no-ff because that's what you want 99% of the time. I probably have too many aliases of log :D

Collapse
 
nickytonline profile image
Nick Taylor

Thanks for sharing @rhymes !

Collapse
 
itsasine profile image
ItsASine (Kayla)

I'm a little disappointed git out isn't something like sudo reboot

Collapse
 
rhymes profile image
rhymes • Edited

AHAHHAAHAH thanks for the laughter.

I should probably start aliasing it on colleagues's computers :D

Collapse
 
yucer profile image
yucer • Edited

I usually make aliases only for those that have specific parameters or are compound of more than one command.

In the other cases, I use the shell auto-completion with the TAB key.

Also, for those like this:

alias.s status -s

If you do that very frequent i think it's better a shell alias (gs) than a git alias (git s)

Collapse
 
nickytonline profile image
Nick Taylor

I do have shell aliases for some things, like grabbing a PR locally (fish shell alias)

function copr
        git fetch origin pull/$argv/head:pr$argv; and git co pr$argv;
end

At the end of the day, everyone has their own setups, which is normal. All that matters is that you set things up the way you like that makes you more productive.

Collapse
 
nickytonline profile image
Nick Taylor

I also don't mention it in the post but I have a shell alias for git which is just g, so I'd do g s

Collapse
 
vlasales profile image
Vlastimil Pospichal

gs has an unpleasant collision with GhostScript.

Collapse
 
philnash profile image
Phil Nash

Thanks for the post Nick! There's such a lot in here and I learned about a couple of commands too. The lost and found search is interesting, not a very common use as you said, but something worth remembering just in case.

I just checked my aliases and I was almost disappointed with how few I have!

  st = status
  co = checkout

I do have this function in my .bash_profile though. It allows you to use g in place of git and if you pass no other arguments runs git status. I find it pretty useful.

function g {
 if [[ $# > 0 ]]
 then
     git $@
 else
     git status
 fi
}
Collapse
 
nickytonline profile image
Nick Taylor

Glad you like it. Thanks for suggesting I write it up. I alias git to g as well, but I like how you default to showing status of no git command is passed in. 🔥

Collapse
 
itsdarrylnorris profile image
Darryl Norris

This is my list:

# Git Aliases
alias gs='git status '
alias ga='git add '
alias gb='git branch '
alias gc='git commit'
alias gd='git diff'
alias gcm='git commit -m'
Enter fullscreen mode Exit fullscreen mode

Very simple

Collapse
 
thomasjunkos profile image
Thomas Junkツ

You copied mine XD

Collapse
 
itsdarrylnorris profile image
Darryl Norris

I did copy from somewhere in StackOver flow many many years ago. I am not sure if was from you or not :P.

Collapse
 
bgadrian profile image
Adrian B.G.

I removed my own aliases and went to a more popular list, namely I adopted bash-it framework.

Collapse
 
nickytonline profile image
Nick Taylor

If it makes you more productive going with existing ones, then 💯.

Collapse
 
hoelzro profile image
Rob Hoelz

Out of curiosity, what was the motivation to give up your own aliases in favor of an alias framework?

Collapse
 
bgadrian profile image
Adrian B.G.
  • Reducing the cognitive load mainly (on me, staying up to date, thinking of new aliases, and so on),

  • the fact that more devs are usually better than 1 (bashit being open source),

  • easier to install and

  • increasing the chance that my aliases are on other PCs.

And I didn't saw any disadvantage.

Thread Thread
 
hoelzro profile image
Rob Hoelz

Thanks for answering! I really appreciated the insight, since it's different from how I work, and I like trying to reevaluate my own usage habits from time to time.

Thread Thread
 
bgadrian profile image
Adrian B.G.

Change is always hard, I used those aliases for many years, but it was time to move on once I started to work from multiple workstations and environments (including Cloud9) I had to simplify all my "custom won bubble".

Collapse
 
nickytonline profile image
Nick Taylor

Adding a late one to the list git config --global alias.mend "commit --amend". Calling it mend seems more natural to me and since I alias git to g in my shell, I'm gonna be all about the g mend.

Collapse
 
plutov profile image
Alex Pliutau

One thing I don't like about Git aliases is that when you are on a new environment (coworker laptop, remote server, etc.) they won't work. So it's better to remember original commands.

Collapse
 
hoelzro profile image
Rob Hoelz

My personal take on this is that for many people, you're on a small set of machines 95% of the time, so it's worth it to optimize your setup on that set of machines.

However, I know that my experience isn't universal - if most of the time you're logging into a large number of machines or machines that are ephemeral in nature, my take doesn't really apply!

Collapse
 
nickytonline profile image
Nick Taylor

For my day to day this is generally not an issue, but if I were on a co-worker's machine or a remote server and for some reason I couldn't remember a git command, I'd use the Google 😉

Collapse
 
thomasjunkos profile image
Thomas Junkツ

I love those two to three letter aliases. Life's to short for typing ;)
But I use aliases in my .zshrc where all my aliases live :]

Collapse
 
wallybh profile image
Wallison Santos

I loved all your aliases, except those that commit a generic commit message. Thanks for share.

Collapse
 
nickytonline profile image
Nick Taylor • Edited

Yeah, I don't use those ones too often. I'm considering removing them.

Collapse
 
eljayadobe profile image
Eljay-Adobe

Very timely! I've got to learn git in the near future this year, and the one thing I'm sure I'll be using right away is aliases. Muchos gracias! Спасибо!

Collapse
 
equiman profile image
Camilo Martinez • Edited

I'm confortable with git alias plugin in oh-my-zsh

To see all commands, can use:
alias | grep git