Git CLI extension via aliases
Git CLI extension via aliases
Posted Mar 8, 2026 15:01 UTC (Sun) by jo42 (subscriber, #59640)Parent article: Magit and Majutsu: discoverable version-control
For me, the CLI is the preferred way to interact with git, because it's very extensible with aliases. These aliases proved to be valuable for me:
[alias]
r = rebase --interactive --rebase-merges
rsh = rebase --show-current-patch
reword = !"set -efuC; f() { for i; do git ci --fixup=reword:\"$i\"; done; }; f"
fixup-last = !"set -efuC; \
l=$(git diff -U0 -- "$1" |sed '/^@@/!d; s/^@@ *-//; s/[, ].*//; s/^0$/1/; q'); \
test -n "$l" || f=$1; \
git ci --fixup=$(\
git log -1 --no-patch --format=%H ${l:+-L$l,+1:$1} @{u}.. -- ${f:-} \
) --"
fixup-last-all = !"set -efuC; git status --porcelain |sed '/^[DMR]\\|^.M/!d' |while read -r mode file _ f2; do git fixup-last "$file" ${f2:+"$f2"}; done"
lr = !"set -f; test $# -eq 0 || { b=$1; shift; }; exec git -c diff.noPrefix=true log --reverse \"@{u}..${b:+@^{/^Merge.* '$b\\}^2}\" \"$@\" # ignore appended args"
lro = !"set -f; test $# -eq 0 || { b=$1; shift; }; exec git lr \"${b:-}\" --oneline \"$@\" # ignore appended args"
And I'm using magit's rebase mode and added functions like
(defun git-rebase-push-label ()
"Insert a `git push` for the label at point"
(interactive)
(save-excursion
(beginning-of-line)
(when (looking-at-p "label ")
(let ((inhibit-read-only t))
(insert
"exec git push github --force-with-lease HEAD:refs/heads/"
(let ((lbl (buffer-substring (+ 6 (point)) (pos-eol))))
(if (string-prefix-p "github-" lbl)
(substring lbl 7)
(concat "jo-" lbl)))
"\n"
)))
))
