Git Aliases I Use (Because I'm Lazy)

I really dislike typing out git commands, even the short ones.

I finally started using Git more heavily a few years ago when I first began building some of my bigger side projects. Now, it’s true that typing git status and git push is pretty easy, but if you’ve got some Git experience you know some commands can get rather long.

The one that always got me was:

$ git commit --amend --no-edit

This amends your staged changes into your most recent commit without changing its commit message (so Git won’t open a text editor!). My most common use case for it was fixing changes I’d just committed. Maybe I was just careless, but I’d often finish a commit only to find a typo or debug line not 30 seconds later 😠.

Typing all 28 characters of git commit --amend --no-edit gets old pretty fast. I’m pretty into optimizing things (even when I probably shouldn’t be 🤷), so one day I procrastinated by thinking about ways to optimize my Git commands…

My Git Aliases

If you google something like ”shorten git commands,” you’ll quickly find out about Git Aliases. Turns out, shortening commands is built into Git! All you have to do is tell Git what you want to alias. For example, you can shorten status to s by copy and pasting this line into your terminal:

git config --global alias.s status

What that command actually does is update your .gitconfig file, which stores global Git configs:

  s = status

Now, whenever you type in the alias s, Git will automatically replace it with status!

Here’s a collection of my favorite Git Aliases:

  s = status
  d = diff
  co = checkout
  br = branch
  last = log -1 HEAD
  cane = commit --amend --no-edit
  lo = log --oneline -n 10
  pr = pull --rebase
My .gitconfig
git aliases
git config --global alias.s status
git config --global alias.d diff
git config --global checkout
git config --global branch
git config --global alias.last "log -1 HEAD"
git config --global alias.cane "commit --amend --no-edit"
git config --global "pull --rebase"
git config --global alias.lo "log --oneline -n 10"
You can copy and paste these to use my aliases!

Finally, there’s one more shorthand I like to use:

# ... other stuff

alias g=git
You can use any text editor to add this to your .bash_profile. See: Linux alias command.

This is a Bash Alias and does exactly what you think it does. If you use a different shell, you can probably do this with a similar feature (e.g. Zsh Aliasing).

You’re ready. Using Git looks like this now:

$ g s
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
$ g br
* master
$ g co -b new-branch
Switched to a new branch 'new-branch'
$ g lo
Author: Victor Zhou <>
Date:   Mon Aug 26 01:16:49 2019 -0700

    Bump version to 1.1.1

Is this actually useful though…

Maybe? Depends on the person. It’ll save you a little time if you’re like me and do weird stuff like habitually spam “git status”:

My opinion is that it’s a small price to pay (~30 seconds of setup on each new machine) for a nice quality of life improvement that makes you feel fast and efficient. How much time you actually save is debatable though…

Some Quick Maths

Let’s get a ballpark estimate of the true amount of time saved. I type around 135 words per minute, so assuming an average of 4 characters per word that’s

135460=9\frac{135 * 4}{60} = \boxed{9}

characters per second.

Here’s a table of how many characters my most commonly-used shortcuts save:

Original commandShortened commandCharacters saved
git statusg s7
git diffg d5
git checkoutg co8
git branchg br6
git log -1 HEADg last9
git commit --amend --no-editg cane20

Next, I used the history command to see my 500 most recent commands. Here’s the breakdown:

CommandTimes used
g s155
g d47
g co19
g br26
g last11
g cane2
Other Git commands94
Non-Git commands146

Each of the 94 “other Git commands” saved 2 characters (since I shorten git to g), so the total # of characters saved was:

CommandTimes usedCharacters savedTotal characters saved
g s15571085
g d475235
g co198152
g br266156
g last11999
g cane22040
Other Git commands942188
1085+235++40+188=19551085 + 235 + \ldots + 40 + 188 = \boxed{1955}

characters saved, an average of 1955354=5.5\frac{1955}{354} = \boxed{5.5} characters per Git command. Assuming I type ~100 Git commands in an average 8-hour workday, that’s 550 characters saved, which converts to about one minute saved per day (using my earlier average typing speed of 9 chars/sec).

Ok, so this isn’t that practically useful. 😢

But, let me reiterate what I said earlier: it makes you feel efficient, and maybe there’s some kind of placebo effect that actually makes you more productive.

What do you think? Do you use aliases, and why or why not? What other aliases do you like? Feel free to discuss below!

UPDATE: There’s some good discusion in this post and in the comments section below. I recommend giving those a read!


As I was writing this post, I realized there were 3 more Git commands I often use that I’d been neglecting:

$ git add .
$ git commit -m 'message'
$ git reset --hard

I’m going to add those to my Git Aliases!

git aliases
git config --global alias.a "add ."
git config --global "commit -m"
git config --global alias.rh "reset --hard"

I write about ML, Web Dev, and more topics. Subscribe to get new posts by email!

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

This blog is open-source on Github.

At least this isn't a full screen popup

That'd be more annoying. Anyways, subscribe to my newsletter to get new posts by email! I write about ML, Web Dev, and more topics.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.