Just enough terminal
Last updated
Git is used by typing commands in a terminal. You need about six of them, and this lesson teaches all six: where am I, what's here, go there, make a folder, and two keys that save a lot of typing.
By the end of this lesson you can
- Say which folder you're in, and list what's in it
- Move between folders with cd, including .. and ~
- Make a folder with mkdir
- Read an error message and fix the command
What a terminal is
A terminal is a window where you type commands instead of clicking. You type a line, press Enter, and the computer runs it and prints what happened. The text before where you type, often ending in $ or >, is the prompt. Many prompts show the folder you're in.
Git has buttons in many editors and apps, but every one of them runs the same commands underneath, and Git's own documentation, error messages and help all use the commands. Learn them once and every Git tool makes sense.
You'll open a real terminal on your own computer in lesson 1.3. Until then, the terminal in this page is enough. It understands the commands in this lesson and Git's own.
Where am I, and what's here?
A terminal is always "in" one folder, called the current folder (or working directory). Two commands tell you about it:
pwd(print working directory) prints the full name of the folder you're in.ls(list) prints what's in it. Folders are shown with a/at the end in this sandbox.
Your home folder is /home/ana here. On your own computer it's something like /Users/ana on a Mac or C:\Users\Ana on Windows.
Try both. The tree on the right shows where you are.
- Type
pwdto see where you are - Type
lsto see what’s here
You are in your home folder, /home/ana. Git is installed and set up.
Your folders
- /home/ana◀ you are here
- kusina/
- adobo.md
- sinigang.md
- photos/
- lola-birthday.jpg
- notes.txt
- kusina/
Moving around: paths, .. and ~
cd (change directory) moves you into a folder: cd kusina. A few short names help:
| You type | It means |
|---|---|
cd kusina | go into the folder kusina, inside the one you're in |
cd .. | go up one level, to the folder this one is in |
cd ~ or just cd | go to your home folder |
cd ~/kusina | go to kusina in your home folder, from anywhere |
A folder's name with the folders above it, like /home/ana/kusina, is its path. mkdir (make directory) makes a new folder: mkdir notebook.
Go into kusina and look around, come back up, then make a new folder and go into it.
- Go into
kusinaand list what’s in it - Go back up to your home folder with
cd .. - Make a folder called
notebookand go into it
You are in your home folder, /home/ana. Git is installed and set up.
Your folders
- /home/ana◀ you are here
- kusina/
- adobo.md
- sinigang.md
- photos/
- lola-birthday.jpg
- notes.txt
- kusina/
The sandbox keeps you at the top of each project folder, which is all this course needs. Your own computer lets you go anywhere.
Two keys that save typing
- Tab completes names. Type
cd kuand press Tab, and the terminal fills inkusina/. If more than one name fits, it shows them all. Completion also stops typos, because it only fills in names that exist. - The up arrow brings back earlier commands. Press it to get your last command back, again to go further back, then edit it and press Enter.
Both work in this sandbox and in every terminal in this course. Try them in the terminal in step 3.
Spot the trap: the wrong folder
Commands act on the folder you're in. Running one in the wrong folder is the most common terminal mistake, and with Git it can be a big one, as you'll see in lesson 1.4.
pwd /home/ana cat adobo.md cat: adobo.md: No such file or directory
Ana opens a terminal and types cat adobo.md to show the adobo recipe. The terminal says No such file or directory.
What happens if…
Errors in a terminal are usually short and exact. Read the last line first: it names the command that failed (cat), the thing it couldn't find (adobo.md), and why.
Check what you learned
Sources
Every command on this page behaves as these pages describe, and the sandbox prints what Git 2.55 prints. Hosting features (pull requests, protected branches) come from the host’s own documentation.
- Pro Git: The Command Line: why this course, like most Git documentation, uses the command line
- GNU Bash manual: the shell on Linux, in Git Bash, and close to macOS's zsh: cd, ~, history and completion
- GNU Coreutils: ls invocation: listing a folder
- PowerShell: Set-Location (cd): cd in PowerShell on Windows
- Terminal User Guide for Mac: opening and using Terminal on macOS