DEV Community

Mykola Harmash
Mykola Harmash

Posted on • Updated on

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
Enter fullscreen mode Exit fullscreen mode

micro@2x

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.

diff-so-fancy@2x

Less clutter and more information. Install it and modify the config:

git config --global core.pager "diff-so-fancy | less --tabs=4 -RFX"
Enter fullscreen mode Exit fullscreen mode

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.

git-jump

No setup required, just install and use.


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>
Enter fullscreen mode Exit fullscreen mode

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.

fixup


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.

Latest comments (3)

Collapse
 
melezhik profile image
Alexey Melezhik • Edited

Hey. thanks for sharing. there are some plugins for git at sparrowhub.io which I also find useful in my daily tasks. For example, git-curent-branch, commit and push.

Collapse
 
ophasnoname profile image
Arne

Thanks for git jump!

Collapse
 
mykolaharmash profile image
Mykola Harmash

Hey, thank you for trying it out! In case you have issues of feature requests, please create a GitHub issue, I'll be happy to help.