The Invent with Python Blog

Fri 18 September 2020

Two Weird Tricks to Help Learn the Git Command Line

Posted by Al Sweigart in misc   

TL;DR: Open two terminal windows and run watch "git status" in one and watch "git log -oneline" in the other so you can get live feedback as you enter Git commands.

Version control is a necessary skill for all software developers, and GUI tools for a version control system like Git make Git easy to use. But you'll often only have access to a command line, so it's still important to learn Git's command line commands. Here's two tricks (invent by a programmer!) you can do to make learning and using the Git command line easier.

The git status command shows which files are unmodified, modified, or untracked while the git log --oneline command shows the first line of every commit message. This is useful information to have, and you'll constantly run these commands as you use Git.

To make this easier, you can have the watch command run these automatically. The watch command repeatedly runs a command you give it, refreshing the screen with the command's output. Open a new terminal window, and run watch "git status" to have an automatically updated view of the Git repo's status. In another terminal window, run watch "git log --oneline" to see a log that is automatically updated every time you commit changes.

(These tricks aren't weird, but I wanted to follow the clickbait headline template in an attempt at humor that will surely date this article.)

The watch command comes standard with macOS and Linux. However, you'll have to download watch.exe separately on Windows and place it in a folder in the system PATH. (If you don't know what that is, you can always place it in C:\Windows if you have an admin account.)

 

Learn to program with my books for beginners, free under a Creative Commons license:

Take my Automate the Boring Stuff with Python online Udemy course. Use this link to apply a 60% discount.