Git Rebase is my only workflow because it leads to clean Git histories, automatic release notes, improved team/stakeholder communication, leveling up of new team members, and so much more. This is especially true when coupled with Git Lint and Milestoner.
One of many tricks, when rebasing, is to reduce typing as much as possible. This article will teach you how to configure Git to use abbreviations to speed up your workflow and why this configuration is important. ⚡️
Quick Start
To quickly configure Git with abbreviations enabled, run the following in your terminal:
git config --global rebase.abbreviateCommands true
That’s it! To learn more about this simple change, read on.
Setup
To set the stage, we can use Rubysmith to quickly build a demo Ruby project skeleton:
rubysmith build --name demo
cd demo
If we look at our Git log, we’ll see we have a single commit:
git log
# Added project skeleton
Great, now we can make modifications:
git switch --create tutorial
touch one.txt
git add .
git commit
touch two.txt
git add .
git commit
I’ll assume, when committing the above changes, you used the following Git commit messages:
Added first tutorial file For demonstration purposes only.
Added second tutorial file For demonstration purposes only.
With the above in place, you should now have a tutorial feature branch commit history that looks roughly like the following:
Added second tutorial file Added first tutorial file
Granted, these commits are silly but are enough to play with the Git Rebase editor.
Rebasing
To rebase, run:
git rebase --interactive main
You’ll then be greeted with the following list of commits in your editor that will look similar to following:
pick b0585fce6314 Added first tutorial file pick 0718854f73ab Added second tutorial file
The pick command is the default command but you can change the commands to reword, fixup, squash, etc. as shown in the full command list displayed at the top of this article. Herein lies the problem: that’s too much typing!
To fix, we can update our global Git Configuration to ensure Git Rebase always uses abbreviated comands:
git config --global rebase.abbreviateCommands true
Now, when we rebase, we see only single letter (abbreviated) commands:
p b0585fce6314 Added first tutorial file p 0718854f73ab Added second tutorial file
Much better! Now you can always work within the Git Rebase Editor using only a single letter command for any of the following commands:
-
p (pick)
-
r (reword)
-
e (edit)
-
s (squash)
-
f (fixup)
-
x (exec)
-
b (break)
-
d (drop)
-
l (label)
-
t (reset)
-
m (merge)
-
u (update-ref)
Since the command list is small, using a single letter for commands makes rebasing a breeze. Thanks, Git. 🙇🏻♂️
Conclusion
This is one of those easy configuration changes — and one I’ve used for many years — that speeds up your workflow considerably. Enjoy!