The terminal for humans
Beginner Git CLI VS Code UI IntelliJ UI
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 oldcmddoes 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.
Press Ctrl+` (the backtick, under Esc) or View → Terminal. The terminal opens inside the folder you have open, which is exactly where Git commands need to run. To open a terminal in a specific subfolder, right-click it in the Explorer and choose Open in Integrated Terminal.
Press Alt+F12 (⌥F12 on macOS) or View → Tool Windows → Terminal. It starts in the project folder. Right-click a folder in the Project view → Open In → Terminal to start there instead.
GitLab has no terminal for the files on your computer. What it has is the Web IDE for editing files in the browser (lesson 7.8). Every command in this course runs on your own machine.
GitHub has no terminal for your local files either. Codespaces (a paid cloud machine) provides a terminal in the browser for some teams; if yours uses it, the commands in this course work there unchanged.
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:
$ pwd/Users/youpwd 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
$ lsgit-practicels 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.
$ ls git-practice/trailguideCONTRIBUTING.md
README.md
data
docs
src
testsMove: cd
$ cd git-practice/trailguide
$ pwd/Users/you/git-practice/trailguidecd 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:
$ cd nowherecd: 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
$ cd ~/git-practice
$ mkdir notes
$ lsnotes
trailguidemkdir 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
$ 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,mkdirand many Git commands, silence means success. - Information, like the output of
lsorgit status. Read it before typing the next command. - An error. Usually contains
error,fatal,not foundorNo 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
pwdandlsto 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
cmdon Windows for this course.
Common mistakes
- Spaces in folder names.
cd My Documentsfails 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 repositorymeans you are not inside a project.cdinto it first. - Case. On Linux, and in Git,
README.mdandreadme.mdare 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.
- Open a fresh terminal (you start in your home folder).
- Move into the playground in one command using
~. - List the
docsfolder. - 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
$ cd ~/git-practice/trailguide
$ ls docsfaq.md
getting-started.md
images$ cd ../..
$ pwd/Users/youcd ../.. goes up two levels in one step: from trailguide to git-practice, then to your home folder.