- One Tip a Week
- Posts
- One Tip a Week: A git alias for showing your git aliases
One Tip a Week: A git alias for showing your git aliases
This week’s tip of the week is a git alias to show your git aliases. If you’re new to git aliases read up more on git aliases in the official git documentation.
A couple weeks ago, I showed you how to add some git aliases for Conventional Commits. Now let’s list those aliases by creating another git alias! We’re going to call our new git alias aliases
.
git config --global alias.aliases "! git config --get-regexp ^alias\\. | sed -e s/^alias\\.// -e s/\\ /\\ =\\ /"
The TLDR is it’s pulling out the list of aliases from your global git configuration. You can run that command, but it’s a lot to remember, although if you ran it before, maybe you just want to use mcfly. 😎
So this adds a new alias to your git global configuration. Now if you run git aliases
, you get a list of all your aliases! Here’s mine if you’re curious. I find this handy when I forget some of my less used git aliases.
❯ g aliases
a = add .
b = branch
bi = bisect
ci = commit -m
co = checkout
colast = checkout -
db = branch -D
laf = fsck
pf = push --force-with-lease
psu = push --set-upstream
ra = rebase --abort
rc = rebase --continue
remotes = remote -v
renb = branch -m
s = status -s
stashes = stash list
unstash = stash pop
vc = clean -dfx
mend = commit --amend
last = log -1 HEAD
lc = diff HEAD^ HEAD
rhh = reset --hard HEAD
rh = reset
sfc = diff-tree --no-commit-id --name-only -r
aliases = ! git config --get-regexp ^alias\. | sed -e s/^alias\.// -e s/\ /\ =\ /
chore = !chore() { git commit -m "chore: $1"; }; chore
fix = !fix() { git commit -m "fix: $1"; }; fix
feat = !feature() { git commit -m "feat: $1"; }; feature
featb = !featurebreak() { git commit -m "feat!: $1"; }; featurebreak
test = !test() { git commit -m "test: $1"; }; test
docs = !docs() { git commit -m "docs: $1"; }; docs
conf = config --global --edit
trigger = ! git commit --allow-empty -m 'chore: trigger build'
laf = fsck
ec = config --global --edit
sn = !f() { git stash push -m "$1"; }; f
un = !f() { git stash apply stash^{/$1}; }; f
That’s it! Short and sweet. Until the next one!