Full Stack JS

Chapter 18
0%

Chapter 18: Git & GitHub

Learn version control to track changes, collaborate with others, and never lose your work again.

What is Git?
Basic Commands
Branches
GitHub
Pull Requests
Quiz

What is Git?

Git is a time machine for your code. Imagine you are writing a book and you could save a snapshot of the entire manuscript at any point. If you mess up chapter 5, you can go back to the snapshot where chapter 5 was perfect. Git lets you do exactly that with code — save snapshots, go back in time, and even work on multiple alternate versions simultaneously.

Git is a version control system (VCS). It tracks every change you make to your project files. Here is why you need it:

Key Concepts

Think of Git like taking photo snapshots. Each commit is a photograph of your entire project at that moment. You can flip through your photo album (commit history) to see how your project evolved over time.
TermWhat It MeansAnalogy
Repository (repo)Your project folder tracked by GitA photo album
CommitA saved snapshot of your changesOne photo in the album
Staging areaChanges ready to be committedArranging people for a group photo
BranchA parallel version of your codeAn alternate timeline
MergeCombining two branches togetherMerging two timelines

Basic Commands

These are the commands you will use every single day as a developer:

Terminal — Setting Up Git
Terminal — The Core Workflow
The Git Workflow

Working Directory  ⟶  git add  ⟶  Staging Area  ⟶  git commit  ⟶  Repository
(your files)                 (ready to save)                  (saved snapshot)
Write good commit messages! Bad: "fixed stuff" or "update". Good: "Fix login form validation for empty email field". Your future self (and teammates) will thank you.

The .gitignore File

A .gitignore file tells Git which files to ignore (never track). Create it in your project root:

.gitignore — Files to Ignore

Branches

Branches are like parallel universes. In one universe (branch), you are working on a new feature. In another universe (the main branch), your stable code remains untouched. When the feature is ready and tested, you merge the two universes together. If the feature turns out bad, you simply delete that universe — your main code was never affected.
Terminal — Working with Branches
Rule of thumb: Never work directly on main. Always create a new branch for each feature or bug fix. This keeps main stable and makes it easy to review changes.

GitHub

Git runs on your local computer. GitHub is a website that hosts your Git repositories in the cloud so you can share, collaborate, and back up your code.

Terminal — Connecting to GitHub
CommandDirectionWhat It Does
git pushLocal → GitHubUpload your commits
git pullGitHub → LocalDownload latest changes
git cloneGitHub → LocalDownload entire repo (first time)

Pull Requests

A pull request (PR) is like asking a friend to review your essay before submitting it. You write your changes on a separate branch, push it to GitHub, and then open a PR asking your team to review the code before it gets merged into main. This way, bugs get caught before they reach production.
Terminal — Pull Request Workflow

PR Best Practices

📝 Chapter 18 Quiz

1. Which command saves a snapshot of your changes?

git add
git push
git commit
git save

2. What is the staging area?

A temporary folder on GitHub
A holding area for changes that will be included in the next commit
A backup of your repository
The main branch

3. Why should you create a new branch for each feature?

To keep main stable and isolate new work
Because Git requires it
To make the repository larger
Branches are only for teams, not solo developers

4. What should you put in a .gitignore file?

Your most important source code files
A list of team members
Git configuration settings
Files Git should not track (node_modules, .env, etc.)

5. What is the purpose of a pull request?

To download code from GitHub
To request code review before merging into main
To pull changes from another branch automatically
To delete a branch
← Chapter 17: Full Backend Project Chapter 19: Environment & Build →