This lesson is for PRO members.

Unlock this lesson NOW!
Already subscribed? sign in

Practical Git: Navigate git command pager output with Unix less commands

2:03 Tools lesson by

When using a git command that can have a large amount of output (like git log, git diff, or git blame), Git opens the command output in our terminal "pager"; on most modern Unix-based systems, the default pager will be "less". Learning a few less commands will help us deal with this git command output that opens in the pager. In this lesson, we show some of the most useful of the less commands: q (quit), j (down), k (up), Ctrl f (forward), Ctrl b (backward), /{search} (search), and n/N (next/previous search result).

This lesson only covers some of the most critical less commands; there are more commands available. A good chunk of the commands (and "motions") of the Unix pagers are also used by vi (or vim) and other Unix programs.

Get the Code Now
click to level up

egghead.io comment guidelines

Avatar
egghead.io

When using a git command that can have a large amount of output (like git log, git diff, or git blame), Git opens the command output in our terminal "pager"; on most modern Unix-based systems, the default pager will be "less". Learning a few less commands will help us deal with this git command output that opens in the pager. In this lesson, we show some of the most useful of the less commands: q (quit), j (down), k (up), Ctrl f (forward), Ctrl b (backward), /{search} (search), and n/N (next/previous search result).

This lesson only covers some of the most critical less commands; there are more commands available. A good chunk of the commands (and "motions") of the Unix pagers are also used by vi (or vim) and other Unix programs.

Avatar
Frederic Rey

So far I've been using git mostly on my own so I've never been confident working with others. A really well explained course, haven't finished yet but I've learned a lot already, thanks!

Avatar
Trevor

Thank you Frederic!

In reply to Frederic Rey
Avatar
Max

I'm just wondering why in XXI century someone still about to use command line interfaces, type as many characters as Shakespeare poems have and browse miles of useless info like commits hashes? Hey, c'mon, welcome to the world of tomorrow with GUI!
Anyway, very useful course. Thank you.

In reply to egghead.io

In our command line, we're inside of a directory called "Utility Functions," which is a git repository. If we run a git command that has a lot of output like git log, it will open up in what's called a "Terminal Pager."

We know that we're inside of the pager program because of the colon at the bottom of the screen. Unless you've changed the pager and use on your computer, you're most likely using the Unix less pager.

Less has a lot of really useful commands that we can use to navigate around our pager. The most important one is q, which brings us back to our main command line prompt. That q stands for quit. After I run the q command, I usually clear my screen.

Let's run git log again to get back into our pager output. We can use our down and up arrows to go up and down one line at a time. We can also use our PageUp and PageDown keys to go up and down one screenful at a time.

We can do the same thing more efficiently using J and K to go down and up one line at a time. We can use Ctrl F as in forward to go forward a screenful, and Ctrl B as in backward to go backward a screenful.

We can search for something specific by using the forward slash, which if you notice at the bottom of the screen changes our prompt to a forward slash. Then type in a search like Trevor. Once we hit Enter, it will highlight all of our search results. We can use the n key as in next to go to the next search result and capital N to go to the previous search result.

For a quick review, I'm going to hit q to quit my pager output. When I run any git command that has a lot of output like git blame, diff, or log, it will open up in my pager. I can navigate by screens with Ctrl F and B, navigate by lines with J and K, search for a specific terms with the forward slash and the term, and then n and capital N to go forward and backward between those search results.

Finally, q to quit and get back to my main prompt.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?