Why You Should Use Git From the Command Line

People who are new to the Git CLI often feel frustrated, this is especially true if they’ve already used Git via a GUI (if you’re experienced with command-line game you could up your game with Git aliases)

It’s hard to blame them, using a Git CLI requires:

  • Remembering many Git commands and how to use them (not to mention their flags).
  • Typing multiple commands to achieve an action that you can very easily achieve using a single button click on a Git GUI.
  • Understanding how Git more or less works

Despite the effort, I believe it can be extremely beneficial in the long run to work with Git from the command line. Here are several reasons why:

You feel comfortable everywhere

A big advantage for using Git CLI is that you work comfortably everywhere, the experience of working on your local computer, a colleague computer or even a remote machine with a different OS feels more or less the same (minus your personal configurations perhaps).

Fully utilizing Git

The big downside of using GUI for Git (IMHO) is that it exposes you to a relatively small interface (whatever part the GUI creator deemed important), this basically means you are not fully interacting with Git and are therefore not familiar with (at least) some of its capabilities. I’ve met some really good developers that used a certain GUI and were not even aware that Git has a staging area. When using the Git CLI you are using the entire Git interface and are therefore able to see the bigger picture, this makes you much more comfortable with Git and will almost certainly expose you to some useful utils like reflog, bisect & git grep (and many more).

The authors of The Pragmatic Programmer sum this idea much better than me:

Many new programmers make the mistake of adopting a single power tool, such as a particular integrated development environment (IDE), and never leave its cozy interface. This really is a mistake. We need to be comfortable beyond the limits imposed by an IDE. The only way to do this is to keep the basic tool set sharp and ready to use.

Git CLI gives you the power of the command line

We often try to reuse & build on top of existing tools and this is no different since you’re already using the command line, you are able to compose your Git flow with many useful command-line tools. From looping over each commit and running tests on it, through easily adding files using FZF to using Ag on your logs — the only limit here is your creativity.

Git CLI enables easier automation & deployment

After using the Git CLI, it’s natural to start automating and scripting your workflow. You can use Git hooks to fail a commit if your tests didn’t pass and even add your Jira ticket ID to the beginning of the commit. This added power allows you to write better deployment script.

What if the transition from GUI to CLI is too much?

Try to incrementally move towards the CLI. Find something you’re doing with your Git GUI and learn how to do just that using the command line, when you feel comfortable with your new skill — look for the next one. The simplest example I could think of was to start adding files via the command-line:

I found this is to be a much easier transition than completely moving from GUI to CLI. I also found Git Ready & Learn Git Branching extremely useful learning resources to make this transition easier.

Let’s recap the advantages of using a Git CLI:

  • Comfortably using Git everywhere (local machine, different OS, someone else’s computer, remote machine etc).
  • Learning to fully use Git and it’s tools.
  • All the command line tools (FZF, bash one-liners etc) are at your disposal.
  • Enables scripting & automation.

I’ll be happy to hear your thoughts on this 🙂

Programming, sports & a bad sense of humor

Programming, sports & a bad sense of humor