My favorite git aliases - revisited
I got some decent code review on /r/programming for My favorite git aliases, especially from /u/doener.
As a result, I’ve revised and simplified some of my aliases. Here’s what changed:
git amend
to add content to the most recent commit
git commit
has a simpler flag to add the more recent commit without editing
the commit message:
- commit --amend --reuse-message=HEAD
+ commit --amend --no-edit
git workon
to get a fresh start
This alias used an opaque git symbolic-ref
command to try to identify the
correct upstream branch. Luckily, git has this information already as
origin/HEAD
. That pointer is set when you clone a repo, and refers to the
latest commit on the default branch of that server. As long as we’ve cloned our
repo from a server, this will point at the right place.
- !f(){ git fetch && git checkout -b "$1" $(git symbolic-ref refs/remotes/origin/HEAD | sed "s@^refs/remotes/@@"); };f
+ !f(){ git fetch && git checkout -b "$1" origin/HEAD; };f
We still have the bash f
function trick to run multiple commands, but it got a
lot simpler.
git refresh
to integrate early
This alias also used symbolic-ref
and could benefit from origin/HEAD
and
some feautes of git pull
that I was unaware of.
- !f(){ git fetch && git stash && git rebase $(git symbolic-ref refs/remotes/origin/HEAD | sed "s@^refs/remotes/@@") && git stash pop; };f
+ pull --rebase --autostash origin HEAD
That’s way better! Folks on reddit strongly preferred these kind of “plain” aliases that don’t entail extra bash shenanigans.