My Git CLI overhaul
I split this out of my 2024 project review because it got too long.
Last year I improved my daily Git experience by writing a bunch of aliases. Here’s a reference for what I’ve done so far (Nix configs).
Contents
Meta
Every command that changes repo state prints the updated state using
git st.Every command that acts on a Git object, like a commit or a branch, opens a fuzzy finder if the object is omitted.
git a
git a FILE+ - Stage the given FILEs.
Inverse: git r.
git amend
git amend - Add the currently staged changes to a given commit.
Asciinema cast of git amend (source).
After a file is staged, git amend brings up a fuzzy-finder showing recent commits.
A commit is selected, and the staged change inserted into that commit.
git ap
git ap - Stage files using interactive patch mode.
git au
git au - Stage all modified files.
git br
git br OPTION* - Branch management.
Prints the current branch name if OPTIONs are ommitted. Otherwise, OPTIONs are passed to git branch.
git co
git co - Commit staged files, opening an editor for the commit message.
Inverse: git undo.
git coe
git coe MESSAGE - Create an empty commit with message MESSAGE.
Inverse: git undo.
git com
git com MESSAGE - Commit staged files with message MESSAGE.
Inverse: git undo.
git ch
git ch BRANCH? - Switch to a branch.
Asciinema cast of git ch (source).
git ch brings up a fuzzy-finder showing available branches.
A branch is selected and switched to.
git chn
git chn BRANCH - Create and switch to branch BRANCH.
git d
git d - Diff unstaged files against staged and committed files.
git ds
git ds - Diff staged files against committed files.
git f
git f - Fetch new changes, and show whether recent commits have diverged.
git f, where the local changes have diverged from the remote changes.
The commits are listed in the same format as git l, but both the local and remote commits are listed, and an ASCII graph highlights the divergence.
git l
git l - Display the 20 most recent commits.
git l.
Commits are listed one per line.
Each line includes: a shortened commit hash, the first line of the commit message, the time since the commit was made, and any branches that point to the commit.
git lg
git lg - Display the 20 most recent commits using an ASCII graph.
See git f for a screenshot of an ASCII graph.
git p
git p - Push the current branch.
git pa
git pa - Push all branches.
git pf
git pf - Force-push the current branch.
git r
git r FILE+ - Unstage staged FILEs.
git re
git re OPTION* - Call git rebase with OPTIONs.
git rec
git rec - Alias for git rebase --continue.
git rei
git rei COMMIT? - Start an interactive rebase.
Uses COMMIT as the base commit if provided.
Otherwise, launches a fuzzy finder to select the base commit.
git reword
git reword COMMIT? - Edit a commit message.
Edits COMMIT if provided.
Otherwise, launches a fuzzy finder to select the commit.
Asciinema cast of git reword (source).
git reword brings up a fuzzy-finder showing recent commits.
A commit is selected, and an editor opens containing that commit’s message.
The message is edited, the editor saved then closed, updating the commit’s message.
git st
git st - Print the repo’s state.
git st.
Modified files are marked with a red “M”, staged files are marked with a green “A”, and new files are marked witha a red “??”.
The command also lists any unpushed commits.
git spop
git spop - Alias for git stash pop.
git spush
git spush - Alias for git stash push.
git undo
git undo - Remove the most recent commit, staging its files.