cyberzeddk

opinions with a slight chance of snow

Git alias and then some

2025-12-18 4 min read Git

Looking back at my old very single post about git aliases made me realize that I have changed quite a few bits since then. It’s not just the aliases anymore, it’s more about my full git configuration.

General configurations

First of a few neat tips and tricks that are just convenient in your day to day life, depending on your taste of course.

Instead of getting long lists git is able to show output in columns which I personally prefer

[column]
    ui = auto

I’m not sure who actually prefers their branches listed alphabetically, I sure don’t. Instead use this config to show the most recently updated branches first

[branch]
    sort = -committerdate

Switch to getting your tags sorted by natural sort instead of plain alphabetical, just way easier to find what you are looking for and not missing a number in alpha sort.

[tag]
    sort = version:refname

I like doing quick diffs in my terminal, hence I want the output a bit different than the default meyers algorithm, hence I’ve switched to using histogram as it performs way better when moving blocks and actually producing readable diffs. Speaking of moved sections of code I prefer my diff to use a different coloring for the moved sections hence the colorMoved setting.

[diff]
    algorithm = histogram
    colorMoved = plain
    mnemonicPrefix = true

It can feel kind of lazy or for some it might even say the next settings are reckless, but I am a strong proponent of having a as clean git repo as possible locally. All my fetches should prune branches and tags that no longer exist on my remote. The all it is really for my rare occurrences of open source work with a multiple remotes.

[fetch]
    prune = true
    pruneTags = true
    all = true

Ever find yourself needed a rebase in the middle of your work that you don’t really want to commit yet? With the autoStash setting git will automatically stash your changes, de a rebase and then pop your changes. Though it can bite you with some very awkward and complex conflicts I find it highly useful…aka I haven’t had the conflicts hit me, yet.

[rebase]
    autoStash = true
    updateRefs = true

If you are a rebaser kindda of person like me, then you might wanna set rebase to true, so you can actually avoid defining --rebase on every pull.

[pull]
    rebase = true

With the many ways you can twist the arm of git I tend to run with a central workflow, hence my default push strategy fits quite well with the upstream setting. The autoSetupRemote is just a nice to have so that when I create a new branch and push it for the first time it automatically sets the remote tracking branch.

[push]
    default = upstream
    autoSetupRemote = true
    followTags = true

Formatting

This bit is probably the section that have eaten most brain cells for me. Spending the first 20 years of my career in a pure Windows environment, though with some PowerShell in the later years, I am soooo not used to these terminal colors and stuff. After tweaking and twisting it over the years I have finally landed on the format that fits my eyes the best. The neat thing you can do is define different pretty formats and then later use them as aliases.

    [pretty]
        slog = format:%C(auto)%h %C(magenta)%ad %C(auto)%d%C(auto) %s %C(green)[%cn]

Aliases

Last but not least the updated collection of my git aliases. Some were in the old post, but some are new. The most interesting ones are those that leverage the previously defined pretty formats. Well not to forget my lovely alias for ammend, it is usually due to forgetting a file or two, so why not use ups as the short alias.

    st = status -s
    aa = add -A
    cm = commit -m
    ups = commit -a --amend
    co = checkout
    cob = checkout -b
    dh = diff HEAD
    wdiff = diff -w --word-diff=color --ignore-space-at-eol
    ls = log --pretty=slog --decorate --date=relative
    ll = log --pretty=slog --decorate --date=relative --numstat
    fl = log -u
    start = !git init && git commit --allow-empty -m \"Initial commit\"