Jessitron’s favorite git aliases

so I can find them here later:

Fast-forward merge

Some people like to git pull, but I never do. That brings new stuff from origin and then merges. I always do these do steps separately: git fetch and then either merge or rebase. The easy case, when I don’t have any local-only commits, is to do a fast-forward merge. That moves my local branch pointer forward to match origin’s, and rearranges my files. I do this with git ff for “fast-forward merge; fail if I have any local commits that I should rebase.”

git config --global alias.ff "merge --ff-only"

Absorb changes into the previous commit

Often I want to slide a quick typo fix into the commit I just made. I can add the files to the cache with git add . (or just a part of the changes with git add -p). Then to mush them into the last commit, I do git fix.

git config --global alias.fix "commit --amend --no-edit"

It’s like, I could type git commit --amend except with the two m’s in commit and the two dashes I always type ammend and get an error. And then it opens the editor and I didn’t want to change the message and I never remember the option for –no-edit. The alias makes it easy.

See also: git home

Display the log graph the way I like it

At any shell prompt, ll must be aliased to ls -l, meaning “give a detailed listing of the files.” I do something similar with git, where git ll means “show me the commit graph with the details I like.”

To define “the details I like,” I make a custom log format. That can look like this:

git config --global pretty.jess "format:%C(#d68c43 dim)%h %C(auto)%d %C(#45a725)%cd %C(white no-dim)%s %C(#68d643)%aN"

This says, “Create a custom format called ‘jess’ which shows: the abbreviated commit hash (%h) in dim brown; the existing pointers to that commit (%d), in the same color scheme you use for --decorate; the commit date (%cd) in dark green; the subject (first line of the log, %s) in white and not dimmed; and the author name (%aN) in obnoxious pink.” It is not actually pretty, so add your own taste by adjusting the colors.

Then I’ll use that in my new alias:

git config --global alias.ll "log --graph --date=short --pretty=jess"

This says, “Create a new alias for ‘ll’ that displays the log in a graph, with dates printed like YYYY-MM-DD, and the format that I defined earlier.”