PTENES
MODULE 1.2

🌿 Git: Saving Your Work

Git is your project's version control. With it, you never lose code again, and you can go back in your project's history to any point where everything worked. Here you'll learn to save versions of your work and sleep easy.

6
Topics
45
Minutes
Zero
Level
Hands-on
Type
1

What Is Version Control

Imagine a Infinite Ctrl+Z for your entire project. Not just for the last character you typed, but for any point in its history: yesterday morning, last week, before that change that broke everything. That's version control. Git keeps a timeline of your project, and every time you save (a "commit"), you create a point you can always go back to.

PROJECT TIMELINE first commit a1b2c3 adds menu d4e5f6 fixes colors 7a8b9c HEAD now e0f1a2 go back in time to any point

🧠 Analogy: An Infinite Ctrl+Z

In a text editor, Ctrl+Z undoes the last thing you typed. But if you close the program, the history disappears. Git is like a Ctrl+Z that never disappears and works for the whole project.

  • β€’Each time you save, it becomes a photo of the project at that moment
  • β€’You can look at any old photo and see what changed
  • β€’If something breaks, you can return to the snapshot from when everything was working
  • β€’Nothing gets lost: the entire history is saved

πŸ’‘ Why Git exists

Before Git, people saved folders called projeto-final, projeto-final-2, projeto-final-AGORA-VAI. A mess. Git solves this: it keeps all the versions organized, shows exactly what changed between them, and lets several people work on the same project without getting in each other's way.

2

Installing and Configuring Git

Before using Git, you need to install it is to specify who you are (name and email). You only do this once per computer. Each operating system has its own way, but the result is the same: the command git starts working in the terminal.

W

Windows

Download the official installer and follow the β€œNext, Next, Next” steps

# Visit the official website in your browser

https://git-scm.com/download/win

# Run the installer. Accept the default options.

# It also includes "Git Bash," a terminal just for Git.

🍎

macOS

Via Homebrew or developer tools

# Option 1: with Homebrew (recommended)

$ brew install git

# Option 2: Apple tools

$ xcode-select --install

🐧

Linux

Through your distribution's package manager

# Ubuntu / Debian

$ sudo apt install git

# Fedora

$ sudo dnf install git

Check the installation and configure who you are

# Confirm that Git is installed

$ git --version

git version 2.43.0

# Tell Git your name (appears in each commit)

$ git config --global user.name "Your Name"

# Tell Git your email

$ git config --global user.email "you@email.com"

# Check what was configured

$ git config --list

user.name=Your Name

user.email=you@email.com

O --global applies to all projects on your computer. You only do this once.

⚠️ Common Error

Problem: You type git --version and you see "git: command not found" (or "not recognized as a command").
Solution: Git wasn't installed, or the old terminal didn't "see" the installation. Close the terminal and open it again. If it still doesn't work, repeat the installation steps for your operating system above.

3

The Basic Cycle: init, add, commit

There’s a three-step cycle you’ll repeat a thousand times in life: start version control in a folder, prepare the files that changed, and commit (save the snapshot). Think of each commit as taking a project photo: you choose what goes into the photo, then take the picture with a caption.

WORKSPACE where you edit index.html style.css git add STAGING AREA what goes into the photo + index.html + style.css git commit REPOSITORY saved history edit β†’ stage (add) β†’ save a snapshot (commit)

git init - Start version control

Inside the project folder, this command creates a Git repository (a hidden folder .git) that will store the entire history.

$ git init

Initialized empty Git repository in /home/usuario/meu-site/.git/

git status - Check the situation

Shows which files have changed and haven't been saved yet. Always use it when you're unsure.

$ git status

On branch main

No commits yet

Untracked files:

index.html

style.css

(use "git add" to include it in the next commit)

Red = file modified but still outside the snapshot.

git add - Choose what goes in the snapshot

# Add a specific file

$ git add index.html

# Add ALL modified files

$ git add .

# Check: now they appear in green

$ git status

Changes to be committed:

new file: index.html

new file: style.css

The point . means β€œeverything in this folder.” Green = ready to go into the photo.

πŸ“· git commit - Take the photo

# -m is the photo caption (commit message)

$ git commit -m "First version of the site"

[main (root-commit) a1b2c3d] First version of the site

2 files changed, 12 insertion(+)

create mode 100644 index.html

create mode 100644 style.css

Done! The photo was saved to the history. The a1b2c3d is the unique "code" for this commit.

βœ“ Good commit messages

  • βœ“"Adiciona menu de navegacao"
  • βœ“"Corrige cor do botao de envio"
  • βœ“Short, clear, say WHAT changed

βœ— Bad messages

  • βœ—"alteracoes" (what changes?)
  • βœ—"asdasd" or "."
  • βœ—Huge commits with 50 mixed files
4

Understanding What Changed: status, log, diff

Git isn't just for saving. It also tells you the project history: what changed just now, what changed over time, and exactly which lines were modified. Three commands answer these questions: status, log e diff.

git status - What changed just now

After editing a file that’s already been committed, the status shows that it was modified:

$ git status

On branch main

Changes not staged for commit:

modified: index.html

(use "git add" to include it in the next commit)

git log - The full story

Lists all commits, from newest to oldest, with author, date, and message:

$ git log

commit 7a8b9c2d (HEAD -> main)

Author: Your Name <voce@email.com>

Date: Mon Jun 16 10:20 2026

Fix the menu colors

commit a1b2c3d4

Author: Your Name <voce@email.com>

First version of the site

# Short version, one line per commit

$ git log --oneline

7a8b9c2 Fixes the menu colors

a1b2c3d First version of the site

To exit the log when it fills the screen, press the q.

git diff - Exactly which lines changed

Shows line by line what was removed (in red, with -) and what's been added (green, with +):

$ git diff

diff --git a/index.html b/index.html

@@ -3,3 +3,3 @@

- <h1>Hello world</h1>

+ <h1>Welcome to my site</h1>

Line with - was the old version; with + and the new one.

πŸ‘ How to read the output in practice

  • β€’status before committing: "What am I saving?"
  • β€’diff before adding: "Are the changes correct?"
  • β€’log later: "how did the project evolve?"
5

Branches: Parallel Realities of the Project

A branch (branch) is a parallel copy of the project where you can test an idea without changing the main version. It’s like having a draft: if the idea works, you merge it back; if it doesn't, you throw it away and nothing was affected.

🧠 Analogy: Parallel Realities

Imagine you could create a parallel universe for your project, test a wild renovation there, and only bring it into the β€œreal” universe if it turns out well. The branch main and the main reality (the one that goes live); each new branch is a testing universe.

main new-color switch -c merge joined

Branch commands

# See which branch you're on and which ones exist

$ git branch

* main

# Create and switch to a new branch at once

$ git switch -c nova-cor

Switched to a new branch 'nova-cor'

# ... here you edit, add, and commit as you like ...

# Return to the main branch

$ git switch main

Switched to branch 'main'

# Bring the changes from nova-cor into main

$ git merge nova-cor

Updating a1b2c3d..7a8b9c2

Fast-forward

βœ“ When to use a branch

  • βœ“Test a new feature without breaking main
  • βœ“Try a different design
  • βœ“Work as a team, each on your own branch

βœ— What to avoid

  • βœ—Make all changes directly on main in serious projects
  • βœ—Let old branches pile up without merging
  • βœ—Switch branches with uncommitted changes
6

.gitignore: What Never to Version

Not everything in your project should go into Git. Passwords, automatically generated files, and huge dependency folders just get in the way (and can be dangerous). The file .gitignore is a list of what Git should ignore completely: it acts as if these files don't even exist.

⚠️ Common Error (and dangerous)

Problem: You commit a file .env with the database password and pushes it to GitHub. Now the password is public for the whole world to see.
Solution: Create the .gitignore before from the first commit and add .env in it. Git will never track this file, and the password stays only on your computer.

πŸ“¦
node_modules

Dependencies (huge)

πŸ”‘
.env

Passwords and keys

πŸ—οΈ
dist / build

Generated files

πŸ’»
.DS_Store

System Junk

Example file .gitignore

Create the file in the project root (touch .gitignore) and put them inside, one rule per line:

# Installed dependencies

node_modules/

# Environment variables and passwords

.env

.env.local

# Files generated by the build

dist/

build/

# Operating system junk

.DS_Store

Thumbs.db

# Logs

*.log

The bar / at the end indicates a folder. The * in *.log means β€œany file ending in .log.”

πŸ’‘ Tip: no need to memorize

There are .gitignore ready-made options for each type of project on the site gitignore.io. You type "node," "python," etc., and it generates the complete file. At first, copy it from there and learn what each line does as you go.

πŸ“š Module Summary

βœ“
Version control - an infinite Ctrl+Z and a project timeline
βœ“
init, add, commit - start, prepare, and take a snapshot of the project
βœ“
status, log, diff - see what changed just now, the history, and every line
βœ“
branches - parallel realities for testing without breaking main
βœ“
.gitignore - never version node_modules, .env, and password files

Next Module:

1.3 - GitHub and Pages (upload your code to the cloud and publish your site for free)