Cover image for My Git Aliases

My Git Aliases

nickytonline profile image Nick Taylor (he/him) Originally published at iamdeveloper.com on ・5 min read

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 Gist”. If you want to read about those posts, check out these:

This post’s birth comes from a gist which is essentially a copy paste of my git aliases.

I’m going to provide my list of git aliases and explain what each alias does, plain and simple. Let’s get started! 🏁 For those new to git aliases, please see the defacto docs on aliases.

Before we get started, why git aliases? Well for one thing, I don’t know about you, but some git commands are hard to remember and also, we’re programmers, which means we’re lazy by default to be efficient. 🐢 —> 🐇

  1. alias.a add . - Running git add will add all files that have changed as staged.

  2. alias.aliases config --get-regexp alias - Running git aliases will show all the aliases you have configured globally in git.

  3. alias.bi bisect - Running git bi will run git’s bisect to help you figure out which commit has a bug.

  4. alias.ci commit -m - This will commit a file with the message you specify, e.g. git ci "awesome commit!".

  5. alias.co checkout - This will checkout the branch you specify, e.g. git co my-awesome-branch

  6. alias.colast checkout - - Running git colast will checkout the previous branch you were working in.

  7. alias.db branch -D - This will delete the branch you specify, e.g. git db my-not-so-awesome-branch. Note that this will only work if the branch you’re deleting is not the one you’re currently working in.

  8. alias.laf fsck --lost-found - Running git laf will bring you to git’s lost and found. I’ll admit that I rarely use this, so perhaps it doesn’t warrant an alias and just some professional Googling.

  9. alias.last log -1 HEAD - Running git last will show you what your last commit was.

  10. alias.nb checkout -b - This will create a new branch, e.g. git nb my-awesome-branch.

  11. alias.pror remote prune origin - Running git pror will do some cleanup on the origin remote via pruning.

  12. alias.pr pull --rebase - This will rebase your current branch with the branch specified, e.g. git pr develop.

  13. alias.ra rebase --abort - Running git ra will abort a rebase. Run this when you’re like, my rebase is currently messed up. Get me outta here!

  14. alias.rc rebase --continue - Running git rc will continue a rebase. You typically run this when you’ve handled any conflicts in a rebase.

  15. alias.pf push --force-with-lease - Running git pf forces a push, but it is a little less destructive than forcing a push. See here for more info on —force-with-lease vs. —force.

  16. alias.psu push --set-upstream - Run this when you want to push a branch for the first time to the remote (typically origin), e.g. git psu origin my-awesome-branch.

  17. alias.remotes remote -v - Running git remotes shows all the remotes currently configured for a repository.

  18. alias.renb branch -m - When you want to rename a branch, run e.g. git renb my-awesom-branch my-awesome-branch.

  19. alias.rhh reset --hard HEAD - The nuclear option. Run git rhh to wipe out all your changes and start from the HEAD.

  20. alias.rh reset --hard - When you specify what to reset to, a hard reset is performed, e.g. git rh HEAD~2.

  21. alias.s status -s - Running git s will give you a more terse status. Instead of this

On branch post/my-git-aliases
Your branch is up to date with 'origin/post/my-git-aliases'.

Changes not staged for commit:
 (use "git add <file>..." to update what will be committed)
 (use "git checkout -- <file>..." to discard changes in working directory)

       modified: src/pages/articles/2018-08-24-my-git-aliases/index.md

no changes added to commit (use "git add" and/or "git commit -a")

You get this

M src/pages/articles/2018-08-24-my-git-aliases/index.md
  1. alias.stashes stash list - Running git stashes shows you all the stashes you have from stashing. e.g.
stash@{0}: WIP on upgrade: bff6257 Destructuring OCD...
stash@{1}: WIP on upgrade: 3d73199 Fixed LiceCap link.
stash@{2}: WIP on upgrade: c2f78g6 Update default title.
  1. alias.unstash stash pop - Running git unstash pops a stash off the list of saved stashes.

  2. alias.vc clean -dfx - Running git vc cleans your git repository, so anything not in git is wiped, e.g. node_modules, settings files which aren’t supposed to be in a repo etc. So BEWARE before you run this.

  3. alias.refactor commit -m 👷Refactor - When running git refactor, a generic refactor message is used for committing any staged files, i.e. 👷Refactor. I’ll probably improve on this to just allow a user to concatenate a custom message to it. But that’s for another day.

  4. alias.formatting commit -m 💅Formatting - When running git formatting, a generic formatting message is used for committing any staged files, i.e. 💅Formatting. I’ll probably improve on this to allow a user to concatenate a custom message to it. But that’s for another day.

  5. alias.comments commit -m 📒Comments - When running git comments, a generic comments message is used for committing any staged files, i.e. 📒Comments. I’ll probably improve on this to allow a user to concatenate a custom message to it. But that’s for another day.

  6. alias.tests commit -m ✅Tests - When running git tests, a generic tests message is used for committing any staged files, i.e. ✅Tests. I’ll probably improve on this to allow a user to concatenate a custom message to it. But that’s for another day.

  7. alias.prum pull --rebase upstream master - Running git prum rebases your current branch off your upstream remote.

  8. alias.mend commit --amend - Running git mend lets you amend a commit.


Posted on by:

nickytonline profile

Nick Taylor (he/him)


Senior software engineer at DEV/Forem. Caught the live coding bug on Twitch at livecoding.ca


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;

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


gs has an unpleasant collision with GhostScript.


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 ]]
     git $@
     git status

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


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.


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