3 Tools and 2 Commands to Improve Your Git Workflow

 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
Image for post

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 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.

Image for post

No setup required, just install and use.

npm i -g git-jump

or

brew tap mykolaharmash/git-jump
brew install git-jump

Now to the commands.

Get a Single File From a Different Branch or Commit

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>

Fixup and Squash

This one requires some habits adjustments, but it’s worth it.

While doing code-reviews this is a very common workflow:

  1. Push changes in a single commit with a nice message
  2. Collect feedback from teammates
  3. Create a bunch of other commits with messages like “fix”, “review”, etc.
  4. 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.

Image for post

Hope you’ve picked something for yourself. Please leave a comment with your personal Git tweaks. 👋

Comments

Popular posts from this blog

Book Review 1