Terminal bridge
- Lesson 1
- 15 min
- Module 1: Understand a repository
Lesson 1 of 15 · Git and Team Development EssentialsTerminal bridge
1. Understand a repository
2. Work with branches and remotes
3. Collaborate through reviews
4. Resolve and recover
5. Release and hotfix practice
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 ready
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.
The terminal is always in one folder
Section titled “The terminal is always in one folder”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-notesRead 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”.
Get a terminal
Section titled “Get a terminal”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.
- Press Cmd+Space to open Spotlight.
- Type
Terminal, then press Enter.
- Go to git-scm.com/install/windows and download the installer.
- Run the installer. Keep the default options on each screen.
- Open the Start menu, type
Git Bash, then press Enter.
- Press Ctrl+Alt+T.
- If nothing opens, open your applications menu and search for
Terminal.
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 $.
Worked example: find your place and move
Section titled “Worked example: find your place and move”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:
pwd/Users/amiraThe terminal is in her home folder. Next, she makes a projects folder there and moves into it:
mkdir projectscd projectspwd/Users/amira/projectsThe 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”:
cd ..pwd/Users/amiraGuided practice: make the practice folder
Section titled “Guided practice: make the practice folder”Make the folders that you use in the rest of this course.
-
Open a new terminal.
-
Show the working directory:
Terminal window pwdThe output is your home folder.
-
Make a folder for your projects. If a
projectsfolder exists already, skip this step.Terminal window mkdir projects -
Move into the folder:
Terminal window cd projects -
Make a folder for this lesson, and move into it:
Terminal window mkdir terminal-practicecd terminal-practice -
Check where you are:
Terminal window pwdThe output ends with
/projects/terminal-practice. -
List the contents:
Terminal window lsThe output is empty, because the folder is new.
Your turn: use one command
Section titled “Your turn: use one command”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.
Open a terminal from your editor
Section titled “Open a terminal from your editor”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 directoryOn 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:
- Run
pwdto see where you are. - Run
lsto see which folders are here. - Use
cdwith a name from thelsoutput.
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.
Does your answer have the main points of ours?
Sign in and enroll in the course to save your answers. Every check counts toward the certificate.
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.
Does your answer have the main points of ours?
Sign in and enroll in the course to save your answers. Every check counts toward the certificate.
Recap
- A terminal is always in one folder, the working directory.
pwdshows it. - A path is the address of a file or folder.
~is your home folder, and..is the folder above. lslists a folder,mkdirmakes one, andcdmoves to one.- If a command cannot find a folder, check where you are with
pwdandlsfirst.
Next, you install and set up Git, and make your first repository.
Next: Set up Git