Git & Command Line Tutorial · Command Line Basics · Lesson 1 of 20

Git & Command Line Introduction

What the command line is, why developers use it every day, and what Git does. A first look at both.

Create a free account to save this page, take notes and track your progress. Sign in

Why the command line?

The command line (also called the terminal or shell) lets you control your computer by typing commands instead of clicking. Developers use it every day because it's:

  • Fast: one command can rename 500 files or search a whole project.
  • Scriptable: anything you type can be saved and repeated.
  • Universal: servers, containers and cloud machines usually have no graphical interface at all.

On macOS and Linux open Terminal; on Windows use Windows Terminal with WSL (a real Linux shell) or Git Bash. This tutorial uses bash; zsh (the macOS default) works the same for everything here.

Why Git?

Git is a version control system: it records every change to your project, lets you go back in time, work on features in parallel branches, and collaborate through services like GitHub and GitLab. Practically every software team uses it.

A first taste: a folder, a file and a commit
echo "Hello from the command line"
mkdir my-project && cd my-project
git init -b main --quiet
echo "# My Project" > README.md
git add README.md
git commit -m "First commit" --quiet
git log --oneline

Output

Hello from the command line
5e44428 First commit

Run this on your computer — see “Get Started” for setup.

Every example in this tutorial is a real bash script run in an empty folder, shown with its exact output.

Test yourself

What does Git do?

  1. Compiles code
  2. Records the history of changes to your files so you can review, undo and collaborate
  3. Hosts websites
  4. Formats code
Show answer

Answer: Records the history of changes to your files so you can review, undo and collaborate

Was this page helpful?