Let's start with tools. Takes only a couple of minutes to set them up and soon it will be painful to use Git without them.
Micro as Default Editor
Unless you're using Vim as your main IDE, you need something that resembles your GUI editor but on the command line, with standard navigation, mouse support, and syntax highlighting. Micro is exactly that.
Install and set it as your Git editor:
git config --global core.editor micro
diff-so-fancy Instead of Default Diff
Standard diff is fine, but with minimal effort, it can be even better. Take a look, left - standard, right - diff-so-fancy.
Less clutter and more information. Install it and modify the config:
git config --global core.pager "diff-so-fancy | less --tabs=4 -RFX"
git jump for Better Experience With Branches
I've built this tool to fulfill my own need, but the feedback confirmed that other people have the same issues when it comes to dealing with a large number of Git branches.
git-jump puts recently used branches on top of the list, has fuzzy-search, and interactive UI among other things.
No setup required, just install and use.
Now to the commands.
Messed up a file? No need to go to GitHub or stash changes to look it up in a different branch.
git restore --source=<commit or branch> <file path>
This one requires some habits adjustments, but it's worth it.
While doing code-reviews this is a very common workflow:
- Push changes in a single commit with a nice message
- Collect feedback from teammates
- Create a bunch of other commits with messages like "fix", "review", etc.
- Squash all commits into the first one with the clean message
Now, on step 3, use
git commit --fixup=HEAD. This will re-use commit message from the previous commit and add
fixup! prefix to it.
Next, on step 4, use
git rebase -i --autosquash <rebase target>.
--autosquash flag will mark
fixup! commits to be squashed automatically. You just need to save and quit rebase editor.
And sure, set up your own shortcut aliases. Real time-saver.
Hope you've picked something for yourself. Please leave a comment with your personal Git tweaks. 👋
Follow me on Twitter, I post there useful dev stuff.