Git Course 0%

The terminal for humans

Beginner Git CLI VS Code UI IntelliJ UI ≈ 15 min

What you will learn

  • How to open a terminal on each operating system and inside VS Code and IntelliJ
  • The six commands that cover 95% of what Git users need: pwd, ls, cd, mkdir, cat, clear
  • How paths work: absolute, relative, ~, ..
  • How to copy commands from this course safely and read what comes back

After this lesson you can

  • I can move to any folder, list what is in it, and run a command there
  • I can read an error message and tell a "wrong folder" problem from a real one

Why this matters

Every Git command in this course is typed into a terminal, and every Git error message appears in one. You do not need to become a terminal expert. You need to move to the right folder, run a command, and read the answer. That is this lesson, and it takes an afternoon to become natural.

Opening a terminal

  • macOS: press +Space, type Terminal, press Enter. The default shell is zsh.
  • Windows: open the Start menu, type Git Bash, press Enter. Git Bash is installed with Git and understands the same commands as macOS and Linux. (PowerShell also works for most commands in this course; the old cmd does not.)
  • Linux: Ctrl+Alt+T on most desktops, or search for "Terminal".

You are looking at a prompt: some text ending in $ or % (or > in PowerShell) and a blinking cursor. The prompt is the terminal saying "your turn". The course writes $ before every command to mean "type this at the prompt"; the $ itself is not typed.

Where am I? pwd

The terminal is always "in" one folder, the working directory. Commands act on that folder unless told otherwise, so the first question is always where you are:

Terminal
$ pwd
/Users/you

pwd stands for "print working directory". On Windows Git Bash prints /c/Users/you; PowerShell prints C:\Users\you. Directly after opening a terminal you are in your home folder: the one with your Documents, Downloads and so on.

What is here? ls

Terminal
$ ls
git-practice

ls lists the folder's contents. Two useful variants: ls -a also shows hidden items (names starting with a dot, such as .git); ls -l shows one line per item with size and date. You can list another folder without moving: ls git-practice/trailguide.

Terminal
$ ls git-practice/trailguide
CONTRIBUTING.md
README.md
data
docs
src
tests

Move: cd

Terminal
$ cd git-practice/trailguide
$ pwd
/Users/you/git-practice/trailguide

cd means "change directory". Three special names:

You type It means
cd .. go up one level (to the parent folder)
cd ~ or just cd go to your home folder from anywhere
cd - go back to where you were before

A path is the address of a file or folder. /Users/you/git-practice/trailguide is an absolute path: it starts at the root / and works from anywhere. git-practice/trailguide is a relative path: it starts from where you are. ~ is shorthand for your home folder, so cd ~/git-practice/trailguide works from anywhere too.

When the folder does not exist, the shell tells you:

Terminal
$ cd nowhere
cd: no such file or directory: nowhere

(bash phrases it bash: cd: nowhere: No such file or directory.) This is the most common error you will see in the course, and it always means the same thing: check pwd and ls, then fix the path.

Make a folder: mkdir

Terminal
$ cd ~/git-practice
$ mkdir notes
$ ls
notes
trailguide

mkdir makes an empty folder in the current directory. Creating files is your editor's job; from the terminal, printf 'text\n' > file.md creates a file with that content, which the labs use occasionally.

Look inside a file: cat and head

Terminal
$ head -3 trailguide/README.md
# Trailguide

A tiny command-line program that prints hiking trail information for the **Northwind Trails** guide.

cat file prints a whole file; head -3 file prints the first three lines. For anything longer than a screen, use your editor instead.

Clean the screen, repeat a command, stop a command

  • clear (or Ctrl+L) empties the screen. Nothing is undone; only the display is cleared.
  • brings back the previous command; press it several times to go further back. Edit it and press Enter.
  • Ctrl+C cancels a running command and gives you the prompt back.
  • If the screen fills with text ending in a : and the prompt does not come back, you are in a pager (Git uses one for long output). Press q to leave it; Space scrolls down.

Copying commands from this course

Every command block has a Copy button that copies the command without the $. Paste into the terminal with ⌘V on macOS, Ctrl+Shift+V or a right-click in Git Bash and most Linux terminals. Then press Enter.

Before pressing Enter, read the command once and replace placeholders: text shown as branch-name in italics must become your real branch name.

Reading what comes back

Three kinds of answers:

  • Nothing. For cd, mkdir and many Git commands, silence means success.
  • Information, like the output of ls or git status. Read it before typing the next command.
  • An error. Usually contains error, fatal, not found or No such file. The last line is the useful one. Copy it whole when you ask for help.

Windows note: file paths in error messages may use backslashes (C:\Users\you); in commands, Git Bash wants forward slashes (/c/Users/you). Both are the same folder.

Do and don't

Do

  • Start every session with pwd and ls to orient yourself.
  • Use Tab completion for every path.
  • Keep one terminal per project folder; the folder is the context.
  • Read errors from the bottom up.

Don't

  • Don't type the $ from the examples.
  • Don't run commands from a website without reading them.
  • Don't close the terminal while a command is still running (the prompt has not come back).
  • Don't use cmd on Windows for this course.

Common mistakes

  • Spaces in folder names. cd My Documents fails because the shell sees two words. Quote it: cd "My Documents", or let Tab completion escape it for you.
  • Running Git in the home folder. fatal: not a git repository means you are not inside a project. cd into it first.
  • Case. On Linux, and in Git, README.md and readme.md are different files. macOS and Windows are more forgiving, which hides the problem until a colleague on Linux hits it.
  • A stuck pager. Press q.

Try it yourself

Goal: navigate to the playground from anywhere and list its documentation.

  1. Open a fresh terminal (you start in your home folder).
  2. Move into the playground in one command using ~.
  3. List the docs folder.
  4. Go up two levels and confirm where you are.

Expected result: ls docs shows faq.md, getting-started.md and images; after going up two levels, pwd prints your home folder.

Show solution

Terminal
$ cd ~/git-practice/trailguide
$ ls docs
faq.md
getting-started.md
images
Terminal
$ cd ../..
$ pwd
/Users/you
cd ../.. goes up two levels in one step: from trailguide to git-practice, then to your home folder.

Check yourself

1. You typed git status and got fatal: not a git repository. What is the first thing to check?
2. What does cd .. do?
3. The terminal shows a screen of text ending with : and does not respond to your typing. What happened?

Key terms

Terminal Working tree