Happier Git: Aliases
Git is one of those tools that's worth investing in. You're going to be using it multiple times per day, everyday for many years (maybe your whole career). The first steps are to get comfortable with the basics but it's worth getting into the guts.
One place that you can file down some of git's rough edges is in ~/.gitconfig
. This is where git reads off its settings (pro-tip: back up your gitconfig in a dotfiles repo so that you're never stranded without the tooling that feels comfy to you).
I want to show off some of the aliases that I find SUPER helpful in staying sane with git.
git co
permalink
[alias]
co = checkout
If you add one alias let it be git co
. It saves you from having to type git checkout branch-name
a billion times.
git recent
permalink
[alias]
recent = !git for-each-ref --count=35 --sort=-committerdate refs/heads/ --format='%(refname:short)!%(authorname)!%(committerdate:short)' | rs -zc! 35 3
git recent
lists off all of the branches you've been on recently. I find that on my busiest days I might be juggling a half dozen branches between a working branch, an upstream, maybe a branch I'm merging, and someplace I need to cherry pick some commits. When I get moving between branches it can be hard to keep track of them so this command lists off all of my recent branches. It pairs very nice with selecta for interactively choosing a branch.
> git recent
main Nicole Watts 2023-02-24
new_desktop_keypad Nicole Watts 2023-02-09
wb_image Jeremy Wiebe 2022-07-26
master Alex Lopatin 2018-01-19
git changed
permalink
[alias]
changed = whatchanged --abbrev-commit --pretty=format:'%h %cn: %s'
Need to know how a branch is changing over time? I find it helpful to see a listing of which files have changed commit by commit (especially after having been away for vacation). git changed
spits out a commit-by-commit listing of what's changed.
> git changed
324a197c GitHub: Fix fonts on "Choose 1 answer" (#377)
:000000 100644 00000000 58b2f96f A .changeset/lemon-phones-collect.md
:100644 100644 80a7569e 170326f1 M packages/perseus/src/styles/widgets/radio.less
41a67e86 GitHub: Create an demo story show how to integrate the on-screen keypad with ItemRenderer (#371)
:000000 100644 00000000 a845151c A .changeset/calm-crabs-raise.md
:100644 100644 985a31d7 3250e76a M .storybook/main.js
:000000 100644 00000000 d53c9d8e A packages/perseus/src/widgets/__stories__/on-screen-keypad.stories.jsx
6a7f36be GitHub: FEI-4957: Update wonder-stuff (after TS migration) and wonder-blocks (#385)
:000000 100644 00000000 940968e1 A .changeset/thin-bananas-care.md
:100644 100644 d9dab586 e1399b05 M .github/workflows/node-ci.yml
:100644 100644 a0d1b253 0d2e3058 M package.json
:100644 100644 035d18de d2fb1582 M packages/math-input/package.json
:100644 100644 20b2f5f9 34578c4b M packages/perseus-editor/package.json
:100644 100644 5cbf0771 e3db9ba1 M packages/perseus-error/package.json
:100644 100644 bce88f16 4cccc6ca M packages/perseus/package.json
:100644 100644 55824e52 60dfe881 M packages/perseus/src/multi-items/__tests__/__snapshots__/multi-renderer_test.js.snap
:100644 100644 fa8b8fdc ddaacc21 M packages/perseus/src/widgets/__tests__/__snapshots__/definition_test.js.snap
:100644 100644 fa4a75d1 b06f8a11 M packages/perseus/src/widgets/__tests__/__snapshots__/graded-group-set-jipt_test.jsx.snap
:100644 100644 31b073c8 be0a92ac M packages/perseus/src/widgets/__tests__/__snapshots__/graded-group-set_test.jsx.snap
:100644 100644 f3910d86 02bb1b0f M packages/perseus/src/widgets/__tests__/__snapshots__/graded-group_test.jsx.snap
:100644 100644 14994048 67d35f77 M packages/perseus/src/widgets/__tests__/__snapshots__/group_test.jsx.snap
:100644 100644 4981bc0d af62ec28 M packages/perseus/src/widgets/__tests__/__snapshots__/radio_test.jsx.snap
:100644 100644 2b21057a 2a3438d9 M packages/perseus/src/widgets/__tests__/__snapshots__/video_test.jsx.snap
:100644 100644 784550e7 b76ae066 M yarn.lock
git deployup
(from @nedredmond) permalink
[alias]
deployup = !git fetch origin master:DEPLOYBRANCH && git push origin DEPLOYBRANCH:DEPLOYBRANCH
Khan Academy maintains long-lived deploy branches that need to be periodically updated against master. git deployup
does the work of fetching the changs and making sure the deploy branch is updated. If you use this just make sure to update DEPLOYBRANCH
to be your deploy branch.
git aliases
(from @jeremywiebe) permalink
[alias]
aliases = !echo All aliases... && git config --get-regexp ^alias\. | sed -e s/^alias.// -e s/\ /\ $(printf "\043")--\>\ / | column -t -s $(printf "\043") | sort -k 1
My coworker @jeremywiebe introduced me to this totally-clutch alias that reminds you what aliases you have installed. This one is new-to-me but I immedaitely am in love.
> git aliases
co --> checkout
recent --> !git for-each-ref --count=35 --sort=-committerdate refs/heads/ --format='%(refname:short)!%(authorname)!%(committerdate:short)' | rs -zc! 35 3