Git Basics: Clone, Add, Commit

By the end of this lesson you'll be able to run the everyday Git workflow with confidence — clone a project, check its status, stage and commit your changes, read the history and diffs, and keep junk out of your repo with .gitignore .

Learn Git Basics: Clone, Add, Commit in our free Git course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a quick…

Part of the free Git course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.

What You'll Learn in This Lesson

1️⃣ git clone — Download a Project

git clone downloads an entire repository — every file, the full history, and all branches — from GitHub (or any remote server) onto your machine. It's how you start working on a project that already exists. Read this worked example, then try it for real on a public repo.

2️⃣ git status — What Has Changed?

git status is the command you'll run most often. It tells you which files you've changed, which are staged (ready to commit), and which are untracked (brand-new files Git isn't watching yet). When you're unsure what Git is about to do, run git status first — every time.

3️⃣ git add & git commit — The Daily Loop

The add-commit cycle is the heartbeat of Git, and you'll repeat it dozens of times a day. Staging with git add chooses which changes go into the next snapshot; git commit -m saves that snapshot with a message. Staging separately from committing is what lets you split your work into clean, logical commits.

Your turn. The script below stages and commits two edited files — fill in the three blanks marked ___ using the hints, then run it.

4️⃣ git log — Read the History

git log shows your commits, newest first. The raw log is verbose, so almost everyone reaches for --oneline (one commit per line) and adds --graph to draw the branch and merge structure. Together they give you a quick map of how the project got to where it is.

5️⃣ git diff — See Exactly What Changed

git diff shows the actual lines you changed — red for removed, green for added. The key distinction: plain git diff shows changes you haven't staged yet , while git diff --staged shows what your next commit will contain . Reviewing the staged diff before committing is the single best habit for avoiding mistakes.

6️⃣ .gitignore — Keep Junk Out

A .gitignore file lists paths Git should never track — dependencies like node_modules/ , build output, OS junk, and (critically) secret files like .env . Put it in your repo root, one pattern per line. Files matched here simply stop appearing in git status , so you can't commit them by accident.

Your turn. Finish the .gitignore below so Git stops tracking the dependencies folder, a secrets file, and log files. Fill in each ___ line.

📋 Quick Reference

No blanks this time — just a brief and an outline. Run the full status → add → diff → commit → log loop yourself, then check your output against the example in the comments. This is exactly the rhythm you'll use on every project.

Practice quiz

What does git clone do?

  • Creates an empty new repository
  • Stages all your changes
  • Copies an entire repository (files, history, branches) to your machine
  • Uploads your commits to a server

Answer: Copies an entire repository (files, history, branches) to your machine. git clone downloads a whole repository and sets up the origin remote automatically.

After cloning, what is the default remote called?

  • upstream
  • remote
  • source
  • origin

Answer: origin. git clone creates a remote named origin pointing back at the URL you cloned from.

Which command do you run most often to see what has changed?

  • git status
  • git log
  • git diff
  • git show

Answer: git status. git status reports which files are modified, staged, or untracked.

What does git add . do?

  • Commits all changes
  • Stages changes in the current folder and below
  • Deletes untracked files
  • Pushes to the remote

Answer: Stages changes in the current folder and below. git add . stages every change in the current directory and its subdirectories for the next commit.

What is the difference between git add . and git add -A?

  • They are identical in every case
  • git add -A only stages new files
  • git add -A stages every change in the whole repo, including deletions outside the current folder
  • git add . also commits

Answer: git add -A stages every change in the whole repo, including deletions outside the current folder. git add -A stages all changes across the entire repository, including deletions and files outside your current folder.

What does plain git diff show (with nothing staged)?

  • Changes in your working files that are NOT yet staged
  • Only changes already committed
  • The remote's commits
  • A list of branches

Answer: Changes in your working files that are NOT yet staged. git diff shows unstaged working-tree changes; git diff --staged shows what the next commit will contain.

Which flag makes git log show one short line per commit?

  • --graph
  • --all
  • --stat
  • --oneline

Answer: --oneline. git log --oneline prints a compact one-line-per-commit history.

What belongs in a .gitignore file?

  • Your commit messages
  • Paths Git should never track, like node_modules/ and .env
  • A list of branches
  • Your remote URLs

Answer: Paths Git should never track, like node_modules/ and .env. .gitignore lists files and folders Git should never track, such as dependencies, build output, and secrets.

What makes a good commit message?

  • The single word 'update'
  • Random characters
  • A short imperative summary of what changed
  • The current date only

Answer: A short imperative summary of what changed. A clear imperative summary like 'Fix login redirect' makes history easy to read and search later.

You committed a .env secret by mistake. What must you also do besides removing it?

  • Rotate or revoke the leaked key immediately
  • Nothing, deleting it is enough
  • Delete the whole repository
  • Run git clone again

Answer: Rotate or revoke the leaked key immediately. Git keeps full history, so anyone who pulled already has the old value; you must rotate the secret as well.