loading...

3 Tools and 2 Commands to Improve Your Git Workflow

mykolaharmash profile image Mykola Harmash ・Updated on ・2 min read

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

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"

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>

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.

Discussion

pic
Editor guide
Collapse
ophasnoname profile image
Arne

Thanks for git jump!

Collapse
mykolaharmash profile image
Mykola Harmash Author

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.

Collapse
melezhik profile image
Alexey Melezhik

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.