🌿 Essential git
Version control from scratch: understand what git is, master init/add/commit, navigate the history, work with branches, and learn how to use .gitignore. Bonus: let Claude Code make commits for you.
📦 What Git is
Snapshots over time — distributed version control
🎯 Core concept
Git is a system that records snapshots of your project over time. Think of it as a photo album of your code: at any time, you can go back to any photo—and create parallel branches without affecting the others.
Commit timeline: main advances while the parallel branch doesn't interfere.
✓ With git
- ✓Undo any change in seconds
- ✓Work on features without breaking what works
- ✓Complete history of who changed what
- ✓Collaborate without overwriting other people's work
✗ No git
- ✗projeto_final_v2_MESMO_FINAL.zip
- ✗Deleted code you needed → no going back
- ✗Two developers edit the same file → chaos
- ✗Doesn't know what changed since yesterday
🚀 init / add / commit
The three fundamental commands—the workflow you’ll repeat hundreds of times
git init — create the repository
Run it once, at the root of your project. Creates the hidden folder .git/ that will store the entire history.
$ cd meu-projeto
$ git init
Initialized empty Git repository in /meu-projeto/.git/
git add — stage files
Adds files to the "staging area" — the list of what will go into the next commit. Think of it as selecting photos for an album before printing.
$ git add index.html # arquivo específico
$ git add . # todos os arquivos modificados
$ git add -p # modo interativo (seleciona partes)
git commit — save the snapshot
Records the staged files in the history with a descriptive message. Once committed, they’re never lost.
$ git commit -m "feat: adiciona página de contato"
[main 3a4f8bc] feat: adiciona página de contato
2 files changed, 47 insertions(+)
💡 Tip: git status is your best friend
Before any add/commit, run git status. It shows exactly what’s modified, what’s staged, and what’s untracked. It removes the guesswork.
🕐 History and Log
Navigate the project's history — audit, diagnose, revert
History is one of git's most powerful advantages. Knowing what changed, when, and why turns hours of bug debugging into minutes.
$ git log # histórico completo
$ git log --oneline # resumido: hash + msg
$ git log --oneline --graph # com grafo de branches
$ git diff # o que mudou (não staged)
$ git diff --staged # o que vai no próximo commit
$ git diff HEAD~1 # vs commit anterior
$ git show abc1234 # detalhes de um commit específico
$ git blame arquivo.html # quem editou cada linha
⏪ Undoing changes
git restore arquivo.html — discards uncommitted changes to the file
git restore --staged arquivo.html — removes it from staging without discarding it
git revert HEAD — creates a commit that undoes the last one (safe for team use)
git reset --hard HEAD~1 — goes back 1 commit (CAUTION: destroys local changes)
✓ Best practices
- ✓Use
git revertto undo changes in shared repos - ✓Run
git statusegit diffbefore every commit - ✓Commit often — small commits are easier to revert
✗ Avoid
- ✗Never use
--hardon a shared branch - ✗Don't commit with a vague message ("fix", "update", "wip")
- ✗Don't combine several unrelated changes in one commit
🌿 Branches
Work in parallel without worrying about breaking what works
🌿 Branches are cheap in git
Creating a branch doesn't copy files — it's just a pointer to a commit. That's why creating and switching branches is instantaneous, even in large projects.
$ git branch # lista branches
$ git branch feature/login # cria branch
$ git checkout feature/login # muda para branch
$ git checkout -b feature/login # cria E muda (atalho)
$ git switch -c feature/login # alternativa moderna
$ git merge feature/login # mescla na branch atual
$ git branch -d feature/login # deleta branch (já mergeada)
$ git stash # guarda mudanças temporariamente
$ git stash pop # recupera do stash
Feature Branch Flow
Each new feature lives in its own branch. main always stays stable. Merge only after review and tests.
Merge conflicts
When two branches edit the same section, git stops and asks for a manual resolution. The markers <<<<<<< / ======= / >>>>>>> show both sides.
git stash — quick pause
Need to switch branches but have uncommitted changes? git stash temporarily saves everything. git stash pop brings it back.
🚫 .gitignore
What not to version control — protect secrets and keep the repo clean
# Dependências
node_modules/
vendor/
# Segredos e configuração local
.env
.env.local
*.key
credentials.json
# Arquivos de build
dist/
build/
*.min.js
*.min.css
# Sistema operacional
.DS_Store
Thumbs.db
# IDEs
.idea/
.vscode/settings.json
*.swp
⚠️ Never commit secrets
Committed API keys, passwords, and tokens remain visible in the public history forever—even after the file is deleted. Always use environment variables and .gitignore from the first commit.
✓ Always ignore
- ✓
.envand secret files - ✓
node_modules/— installed via npm - ✓Automatically generated build files
- ✓Logs and temporary files
🛠️ Useful Commands
git rm --cached arquivo — stops tracking
git check-ignore -v *.log — why it is ignored
gh repo create — already provides a .gitignore template
🤖 Claude Code Commits for You
Professional commit messages with no effort — automatic Conventional Commits
Claude Code automatically runs the complete git cycle at the end of each task. But understanding what it’s doing—and adjusting when needed—is what separates an advanced user from a beginner.
# Estrutura: tipo(escopo): descrição imperativa
feat: adiciona autenticação com Google
fix(auth): corrige loop infinito no login
docs: atualiza README com instruções de deploy
style: formata CSS segundo BEM
refactor(api): extrai lógica de validação para util
test: adiciona testes para módulo de pagamento
chore: atualiza dependências para versão segura
🤖 How to ask Claude Code
At the end of any task: "Commit the changes with a descriptive message."
For a complete workflow: "Add all files, commit with a Conventional Commits format message, and push to main."
Claude automatically generates something like: feat(pages): adiciona página de portfólio com grid responsivo
✓ Good message
- ✓Imperative: "add," "fix," "remove"
- ✓Describe what it does (not what you did)
- ✓Maximum ~72 chars on the first line
- ✓Clear type: feat/fix/docs/chore
✗ Bad message
- ✗"fix" — what did it fix?
- ✗"update" — generic and useless
- ✗"WIP" committed to main
- ✗"I tweaked a few things"
🎯 Module summary
What you learned
- ✓Git is a snapshot system—not a file-copying system
- ✓Flow:
git add→git commit -m "msg" - ✓History with
git log, changes withgit diff - ✓Branches for safe parallel work
- ✓.gitignore protects secrets and keeps the repo clean
- ✓Claude Code automates commits with Conventional Commits
Next module
With local Git under control, the next step is putting the project on GitHub: create a repository, configure the remote, push, set up SSH, use the gh CLI, and collaborate with PRs.
Module 6.2 — GitHub and repositories→