My Git Aliases

Nick Taylor on August 26, 2018

Photo courtesy of Flickr user cindy Alright, so @philnash roped me into this one. This keeps in line with my other posts that are “Not just a Gis... [Read Full]
markdown guide
 

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

 
 

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

 

AHAHHAAHAH thanks for the laughter.

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

 

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)

 

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.

 

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

 
 

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
}
 

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. 🔥

 

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'

Very simple

 
 

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

 

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

 

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

 

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

 
  • 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.

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.

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".

 

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.

 

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.

 

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!

 

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 😉

 

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 :]

 

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! Спасибо!

 

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

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

 

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

 

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

code of conduct - report abuse