Skip to content

Terminal bridge

  • Lesson 1
  • 15 min
  • Module 1: Understand a repository
Lesson 1 of 15 · Git and Team Development EssentialsTerminal bridge

What you will be able to do

Open a terminal in your project folder, and check where you are. Git commands act on the folder you are in, so this is the first skill you need.

Before you startWhat to know and to have readyAbout 15 minutes

What you need to know

  • Nothing. This is the first lesson of the course. No knowledge of the terminal is necessary.

What you need on your computer

  • A computer with macOS, Windows 10 or 11, or Linux.
  • Permission to install software. On Windows, you install Git, which includes Git Bash, in Get a terminal.
  • Nothing to reset: this lesson does not use a repository, so it has no practice lab.

A terminal is a window where you type commands instead of clicking. You type a command, press Enter, and the computer shows the result as text.

A terminal is always “in” one folder. This folder is the working directory. When you type a command, it acts on the working directory, unless you tell it to use a different folder. A file manager works the same way: the window shows one folder at a time.

A path is the address of a file or folder. It lists each folder from the top of the disk, separated by /. For example, this path points to a folder called ticket-notes:

/Users/amira/projects/ticket-notes

Read it from left to right: start at the top (/), open Users, then amira, then projects, then ticket-notes.

Each user has a home folder, for example /Users/amira. A new terminal usually starts there. The short name for your home folder is ~ (a tilde), so ~/projects means “the projects folder in my home folder”.

Use the terminal for your operating system. On Windows, install Git now, because it includes Git Bash. Git Bash accepts the same commands as macOS and Linux, so every command in this course works the same for everyone.

  1. Press Cmd+Space to open Spotlight.
  2. Type Terminal, then press Enter.

The terminal shows a prompt: a short line of text that ends in $ or %. The prompt means that the terminal is ready for a command. In this course, you type the text after the prompt. You do not type the $.

Amira wants a folder for her course projects. She uses four commands:

Command What it does
pwd Shows the working directory (“print working directory”).
ls Lists the files and folders in the working directory.
mkdir name Makes a new folder called name in the working directory.
cd name Changes the working directory to the folder name.

First, she checks where the terminal starts:

Terminal
pwd
Output
/Users/amira

The terminal is in her home folder. Next, she makes a projects folder there and moves into it:

Terminal
mkdir projects
cd projects
pwd
Output
/Users/amira/projects

The working directory is now projects. The path got longer by one folder, because she moved one level down.

To move one level up, she uses .. (two dots), which means “the folder above this one”:

Terminal
cd ..
pwd
Output
/Users/amira

Make the folders that you use in the rest of this course.

  1. Open a new terminal.

  2. Show the working directory:

    Terminal window
    pwd

    The output is your home folder.

  3. Make a folder for your projects. If a projects folder exists already, skip this step.

    Terminal window
    mkdir projects
  4. Move into the folder:

    Terminal window
    cd projects
  5. Make a folder for this lesson, and move into it:

    Terminal window
    mkdir terminal-practice
    cd terminal-practice
  6. Check where you are:

    Terminal window
    pwd

    The output ends with /projects/terminal-practice.

  7. List the contents:

    Terminal window
    ls

    The output is empty, because the folder is new.

Go back to your home folder with cd ~. Then get to terminal-practice again with one cd command, not two.

Run pwd to check your result. The output must end with /projects/terminal-practice.

Show a hint

A path can contain more than one folder. cd projects/terminal-practice moves down two levels in one step. This is a relative path: it starts from the working directory, not from the top of the disk.

Most code editors include a terminal. In Visual Studio Code, open your project folder with File › Open Folder, then select Terminal › New Terminal. The terminal opens in the project folder, so you do not need cd.

On Windows, set Visual Studio Code to use Git Bash: in the terminal panel, open the drop-down list next to +, and select Git Bash.

Common mistake

No such file or directory

Symptom: you type cd ticket-notes, and the terminal shows this error:

bash: cd: ticket-notes: No such file or directory

On macOS, the same error looks like this: cd: no such file or directory: ticket-notes.

Cause: the folder is not in the working directory. You are in a different folder than you think, or the name is not the same. Names are case-sensitive on most systems: Projects and projects are different folders.

Fix:

  1. Run pwd to see where you are.
  2. Run ls to see which folders are here.
  3. Use cd with a name from the ls output.

If a folder name has a space in it, put quotes around the name: cd "my notes". To prevent this problem, use names without spaces, for example my-notes.

Check your understanding

The working directory is /Users/amira. Amira types cd projects/ticket-notes, then cd .. . What does pwd show now?

Show the answer

/Users/amira/projects. The first command moves down two levels, to /Users/amira/projects/ticket-notes. Then cd .. moves up one level, to projects.

Check your understanding

Practical check: open a new terminal and move to your terminal-practice folder with one command. What do you run to prove that you are in the correct folder?

Show the answer

Run cd ~/projects/terminal-practice, then run pwd. The output must end with /projects/terminal-practice. If you get No such file or directory, use the steps in the common mistake above.

Recap

  • A terminal is always in one folder, the working directory. pwd shows it.
  • A path is the address of a file or folder. ~ is your home folder, and .. is the folder above.
  • ls lists a folder, mkdir makes one, and cd moves to one.
  • If a command cannot find a folder, check where you are with pwd and ls first.

Next, you install and set up Git, and make your first repository.

Next: Set up Git