Mastodon hachyterm.io

As a developer, Git is one of the essential tools in my daily work.

Today I want to share my git aliases and fish abbreviations that make working with Git more comfortable.

In my ~/.gitconfig file:

[alias]
  # Git Commit, and Push — in one step.
  cmp = "!f() { git commit -m \"$@\"; }; f"
  # NEW.
  new = "!f() { git cmp \"📦 NEW: $@\"; }; f"
  # IMPROVE.
  imp = "!f() { git cmp \"👌 IMPROVE: $@\"; }; f"
  # FIX.
  fix = "!f() { git cmp \"🐛 FIX: $@\"; }; f"
  # RELEASE.
  rlz = "!f() { git cmp \"🚀 RELEASE: $@\"; }; f"
  # DOC.
  doc = "!f() { git cmp \"📖 DOC: $@\"; }; f"
  # TEST.
  tst = "!f() { git cmp \"🤖 TEST: $@\"; }; f"
  # BREAKING CHANGE.
  brk = "!f() { git cmp \"‼️ BREAKING: $@\"; }; f"
  # Logline
  lol = log --graph --decorate --oneline
  lola = log --graph --decorate --oneline --all
  # Diff, Status
  df = diff --color=always --color-words --abbrev
  st = status -s
  last = log -1 HEAD
  unstage = reset HEAD --
  pj = !which onefetch && onefetch

The first few are from Emoji-Log, a method to decorate git commits with emojis. What I like about the method is that it uses a small subset of defined emojis and make the commits look prettier.

I also have utility commands, like git st which gives me a condensed version of git status.

The logline commands are useful to show a graph of the commits.

git pj (pj for “project”) uses onefetch, a CLI that displays project information and code statistics. It’s pretty neat.

I also have fish abbreviations that make it easier for me to type common git commands.

One of my favorite ones is gapn which expands to git add --intent-to-add . && git add --patch.

This command shows you all your changes from the last commit with the option to stage hunks.

This blogpost explains how git add --patch works.

I’ll leave a list of my fish abbreviations here:

abbr -a -U -- g git
abbr -a -U -- ga 'git add'
abbr -a -U -- gadn 'git add . && git diff --cached'
# interactive git add
abbr -a -U -- gai 'git add -i'
# git add --patch
abbr -a -U -- gap 'git add -p'
abbr -a -U -- gapn 'git add --intent-to-add . && git add --patch'
abbr -a -U -- gbr 'git branch'
abbr -a -U -- gc 'git commit'
abbr -a -U -- gca 'git commit --amend'
abbr -a -U -- gcm 'git commit -m'
abbr -a -U -- gco 'git checkout'
abbr -a -U -- gd 'git pull'
# git diff
abbr -a -U -- gdf 'git df'
abbr -a -U -- gdif 'git diff'
abbr -a -U -- gdoc 'git doc'
abbr -a -U -- gfom 'git fetch origin master'
abbr -a -U -- gft 'git fetch'
abbr -a -U -- gfu 'git fetch upstream'
# git --intent-to-add
abbr -a -U -- gin 'git add -N .'
abbr -a -U -- glst 'git last'
abbr -a -U -- gmg 'git merge'
abbr -a -U -- gnew 'git new'
abbr -a -U -- gp 'git push'
abbr -a -U -- gpl 'git pull'
abbr -a -U -- gpo 'git pull origin'
abbr -a -U -- gpu 'git pull upstream'
abbr -a -U -- grb 'git rebase'
abbr -a -U -- grs 'git reset'
abbr -a -U -- gst 'git status -sb'
abbr -a -U -- gsw 'git switch'

Abbreviations like gcm are handy: The abbreviation expands to git commit -m, so that I now can type my commit message.