A Quick GitHub Course / Um Curso Rápido de GitHub
English: This is a complete Git course taught in both English and Brazilian Portuguese. All learning materials, interactive CLI tools, and documentation are fully bilingual. The README is organized in two main sections: first in English, then in Portuguese. Use the table of contents below to jump directly to your preferred language.
Português: Este é um curso completo de Git ministrado em inglês e português brasileiro. Todos os materiais de aprendizado, ferramentas CLI interativas e documentação são totalmente bilíngues. O README está organizado em duas seções principais: primeiro em inglês, depois em português. Use o índice abaixo para ir diretamente para seu idioma preferido.
Guia rápido para o dia-a-dia de de versionamento com Git e GitHub
Quick guide for daily version control with Git and GitHub
Uma dica? Imprime e cola na parede da sua mesa!!!
A tip? Print it and stick it on your desk wall!!!
- About the Course (EN)
- Part 1: Fundamentals (EN)
- Part 2: Commands (EN)
- Part 3: Practice (EN)
- Real World Use Cases (EN)
- Best Practices (EN)
- Troubleshooting (EN)
- External Resources (EN)
- Contributing (EN)
- Found an Error? Report It! (EN)
- Sobre o Curso (PT)
- Parte 1: Fundamentos (PT)
- Parte 2: Comandos (PT)
- Parte 3: Prática (PT)
- Casos de Uso Reais (PT)
- Melhores Práticas (PT)
- Solução de Problemas (PT)
- Recursos Externos (PT)
- Contribuindo (PT)
- Encontrou um Erro? Reporte! (PT)
Welcome to the complete Git mini course! Learn from basics to advanced techniques, with theory, practice, and interactive tools.
What makes this course special:
- Bilingual Content: All materials, scripts, and CLI tools are available in both English and Portuguese
- Interactive Learning: Hands-on CLI tools to practice Git commands safely
- Real-World Focus: Practical examples and use cases from actual development workflows
- Progressive Learning: From basic to advanced, with clear progression
- Open Source: Free and open to contributions
All unsupervised learning CLI tools are bilingual!
Git is a distributed version control system created by Linus Torvalds in 2005. It allows you to:
- Track all changes made to your files over time
- Work on different versions of your project simultaneously (branches)
- Collaborate with others without overwriting their work
- Go back to any previous version of your code at any time
Analogy: Think of Git as a "time machine" for your files. You can:
- See what changed and when
- Go back to any point in the past
- Create alternate realities (branches) to test ideas
- Merge different timelines (merge)
Git is NOT:
- A cloud service (that's GitHub, GitLab, etc.)
- Only for programmers (can be used for any text files)
- Complicated (with practice it becomes natural)
GitHub is a web platform that hosts Git repositories in the cloud. It's like a "social network for code".
Main differences:
| Git | GitHub |
|---|---|
| Version control system | Hosting platform |
| Works locally on your computer | Works in the cloud (online) |
| Command-line software | Web interface + tools |
| Free and open source | Free with paid features |
| Created in 2005 | Created in 2008 |
What GitHub adds to Git:
- Remote storage (cloud backup)
- Visual interface for code review
- Pull Requests (collaborative code review)
- Issues (task management)
- Actions (task automation)
- Pages (static site hosting)
- Social collaboration (follow developers, star projects)
Alternatives to GitHub:
- GitLab
- Bitbucket
- Gitea
- SourceForge
Problems without version control:
- "Where's the version that worked?"
- "Who made this change and why?"
- "How do I merge my work with my colleague's?"
- "I lost everything! No backup!"
- Folders full of:
project_v1,project_v2_final,project_v2_final_NOW_IT_WORKS,project_final_final
Git Benefits:
- Complete history: Every change is recorded with date, author, and reason
- Parallel work: Multiple people working simultaneously without conflicts
- Safety: Distributed backup - each clone is a complete backup
- Safe experimentation: Test ideas without fear of breaking what works
- Traceability: Discover when and why each line was modified
- Reversibility: Undo mistakes easily
- Collaboration: Work as a team in an organized way
- Professionalism: Software industry standard
Use cases:
- Software development (primary)
- Technical documentation
- System configurations
- Articles and books (text)
- Academic papers
- Any project with multiple versions
Workflow of how GitHub works
Basic workflow with GitHub work (or shold if the users used it in the right way)
Repository:
- Folder containing your project and all Git history
- Can be local (on your computer) or remote (GitHub, etc.)
Commit:
- A "snapshot" of your project at a specific moment
- Each commit has: unique hash, author, date, descriptive message
Branch:
- An independent line of development
- Allows working on features without affecting main code
- Default branch:
main(ormasterin older projects)
Merge:
- Combine changes from one branch into another
- May generate conflicts that need manual resolution
Working Directory:
- The files you see and edit in your folder
Staging Area (Index):
- Intermediate area where you prepare files for commit
- Allows selective commits (only some files)
Remote:
- Version of repository hosted elsewhere (GitHub, etc.)
- Default name:
origin
File states:
- Untracked: Git is not tracking this file
- Unmodified: Tracked file, no changes since last commit
- Modified: File was modified but not in staging
- Staged: File ready to be committed
For whom: Beginners who never used Git
You'll learn: Create repository, make commits, view history
| Command | Description |
|---|---|
git config --global user.name "Your Name" |
Set your name for all repositories |
git config --global user.email "your@email.com" |
Set your email for all repositories |
git config --list |
Show all configurations |
git --version |
Show installed Git version |
Example:
git config --global user.name "Madson Aragão"
git config --global user.email "madson@example.com"
git config --global core.editor "vim"| Command | Description |
|---|---|
git init |
Create new Git repository in current folder |
git clone <url> |
Copy remote repository to your computer |
Example:
# Create new project
mkdir my-project
cd my-project
git init
# Clone existing project
git clone https://github.com/user/repository.git| Command | Description |
|---|---|
git status |
Show current state of files |
git status -s |
Short status format |
git diff |
Show unstaged changes |
git diff --staged |
Show staged changes |
Example:
git status # See what changed
git diff file.txt # See specific changes| Command | Description |
|---|---|
git add <file> |
Add specific file to staging |
git add . |
Add all modified files |
git add -A |
Add all (including deleted) |
git commit -m "message" |
Create commit with message |
git commit -am "message" |
Add + commit (tracked files only) |
Example:
# Basic workflow
git add file.txt
git commit -m "Add new file"
# Or all at once
git add .
git commit -m "Update documentation"| Command | Description |
|---|---|
git log |
Show complete commit history |
git log --oneline |
Summarized history (1 line per commit) |
git log --graph |
History with visual graph |
git log -n 5 |
Show last 5 commits |
git show <hash> |
Show details of specific commit |
Example:
git log --oneline --graph --all
git log --author="Madson"
git log --since="2 weeks ago"| Command | Description |
|---|---|
git remote add origin <url> |
Connect local repository to remote |
git remote -v |
List configured remotes |
git push -u origin main |
Send commits to remote (first time) |
git push |
Send commits to remote |
git pull |
Fetch and merge changes from remote |
Example:
# Connect to GitHub
git remote add origin https://github.com/user/repo.git
git push -u origin main
# Then just
git push
git pullFor whom: Those who know basics and want to work with branches and collaboration
| Command | Description |
|---|---|
git branch |
List all local branches |
git branch -a |
List all branches (local + remote) |
git branch <name> |
Create new branch |
git checkout <name> |
Switch to another branch |
git checkout -b <name> |
Create and switch to new branch |
git switch <name> |
Switch branch (modern command) |
git branch -d <name> |
Delete branch (if already merged) |
git branch -D <name> |
Force delete branch |
Example:
# Create feature
git checkout -b feature/login
# ... work ...
git add .
git commit -m "Implement login"
# Return to main
git checkout main| Command | Description |
|---|---|
git merge <branch> |
Merge specified branch into current |
git merge --abort |
Cancel ongoing merge |
git merge --no-ff <branch> |
Merge without fast-forward (creates merge commit) |
Example:
git checkout main
git merge feature/login
# If there are conflicts
# 1. Edit files manually
# 2. Remove conflict markers
# 3. git add <resolved-file>
# 4. git commit| Command | Description |
|---|---|
git stash |
Save changes temporarily |
git stash push -m "message" |
Stash with descriptive message |
git stash list |
List all stashes |
git stash pop |
Recover last stash and remove from list |
git stash apply |
Apply stash but keep in list |
git stash drop |
Remove last stash |
git stash clear |
Remove all stashes |
Example:
# Quick context switch
git stash push -m "WIP: working on login"
git checkout hotfix
# ... fix urgent bug ...
git checkout feature/login
git stash pop| Command | Description |
|---|---|
git restore <file> |
Discard changes in file |
git restore --staged <file> |
Remove file from staging |
git reset --soft HEAD~1 |
Undo commit, keep changes staged |
git reset --mixed HEAD~1 |
Undo commit, unstage changes |
git reset --hard HEAD~1 |
Undo commit and discard changes |
git revert <hash> |
Create new commit undoing another |
Example:
# Undo local changes
git restore file.txt
# Undo last commit (keep changes)
git reset --soft HEAD~1
# Undo specific commit (safe for shared)
git revert a1b2c3d| Command | Description |
|---|---|
git tag |
List all tags |
git tag v1.0.0 |
Create lightweight tag |
git tag -a v1.0.0 -m "Version 1.0" |
Create annotated tag |
git push origin v1.0.0 |
Push tag to remote |
git push origin --tags |
Push all tags |
Example:
git tag -a v1.0.0 -m "First stable version"
git push origin v1.0.0For whom: Experienced developers who want to master Git
| Command | Description |
|---|---|
git rebase main |
Reapply current branch commits on top of main |
git rebase -i HEAD~3 |
Interactive rebase (edit last 3 commits) |
git rebase --continue |
Continue rebase after resolving conflicts |
git rebase --abort |
Cancel ongoing rebase |
git pull --rebase |
Pull with rebase instead of merge |
When to use:
- Keep history linear and clean
- Before creating Pull Request
- Update feature branch with main
WARNING: Don't rebase commits already pushed to remote!
Example:
git checkout feature/login
git rebase main
# Clean history before PR
git rebase -i HEAD~5
# In editor: squash, reword, drop| Command | Description |
|---|---|
git cherry-pick <hash> |
Apply specific commit to current branch |
git cherry-pick <hash1> <hash2> |
Apply multiple commits |
git cherry-pick --continue |
Continue after resolving conflicts |
git cherry-pick --abort |
Cancel cherry-pick |
Example:
# Take bugfix from one branch to another
git checkout main
git cherry-pick a1b2c3d| Command | Description |
|---|---|
git reflog |
Show history of HEAD movements |
git reflog show <branch> |
Reflog of specific branch |
git reset --hard <hash> |
Go back to specific commit from reflog |
Example:
# "Lost" commits after reset
git reflog
# HEAD@{2}: commit: Implement feature X
git reset --hard HEAD@{2} # Recover!| Command | Description |
|---|---|
git bisect start |
Start binary search for bug |
git bisect bad |
Mark current commit as bad |
git bisect good <hash> |
Mark commit as good |
git bisect reset |
End bisect |
Example:
git bisect start
git bisect bad # Current commit has bug
git bisect good v1.0.0 # v1.0.0 worked
# Git will test commits in the middle
# For each one you test and mark: git bisect good/bad| Command | Description |
|---|---|
git blame <file> |
Show who modified each line |
git blame -L 10,20 <file> |
Blame specific lines |
git blame -C <file> |
Detect copied lines |
Example:
git blame src/main.py -L 50,60| Command | Description |
|---|---|
git submodule add <url> <path> |
Add repository as submodule |
git submodule init |
Initialize submodules |
git submodule update |
Update submodules |
git clone --recursive <url> |
Clone with submodules |
| Command | Description |
|---|---|
git worktree add <path> <branch> |
Create directory for branch |
git worktree list |
List worktrees |
git worktree remove <path> |
Remove worktree |
Example:
# Work on 2 branches simultaneously
git worktree add ../project-feature feature/new
cd ../project-feature
# Now you have 2 independent directories!Files in .git/hooks/:
pre-commit: Execute before commitpre-push: Execute before pushpost-merge: Execute after merge
Example:
# .git/hooks/pre-commit
#!/bin/bash
npm test # Run tests before allowing commitThis course includes interactive CLI tools to facilitate learning and using Git.
git-learn.sh - Learn Git from scratch
./scripts/git-learn.shContent:
- 12 progressive lessons (basic to intermediate)
- Explanations in Portuguese and English
- Guided practical exercise at the end
- Creates real test repository
For whom:
- Total Git beginners
- Those who want to understand concepts
- Students learning programming
git-cli.sh - Execute Git commands via menu
./scripts/git-cli.shFeatures:
- 13 most common Git operations
- Numbered menu interface
- Confirmation for dangerous actions
- Detects repository automatically
- Shows current branch
For whom:
- Those who want to speed up common tasks
- Beginners who haven't memorized commands yet
- Quick daily use
git-simulator.sh - Simulate Git operations without risk
./scripts/git-simulator.shFeatures:
- Creates temporary test environment
- Simulates complete Git workflow
- Visualizes repository state
- Practice without fear of mistakes
- Environment is destroyed on exit
For whom:
- Those who want to practice without risk
- Git classes and workshops
- Test commands before using in real projects
list-of-comds-how2git.sh - Organized and commented commands
cat scripts/list-of-comds-how2git.sh
# or
vim scripts/list-of-comds-how2git.shFor whom:
- Quick reference
- Copy and paste commands
- Study syntax
# Clone repository
git clone https://github.com/company/project.git
cd project
# View branch structure
git branch -a
# View recent commits
git log --oneline -10
# Create your work branch
git checkout -b feature/my-task# Create branch
git checkout -b feature/login
# Work...
git add .
git commit -m "feat: add login screen"
# More work...
git commit -am "feat: add validation"
# Update with main
git fetch origin
git rebase origin/main
# Send for review
git push -u origin feature/login
# Create Pull Request on GitHub# Save current work
git stash push -m "WIP: login feature"
# Create hotfix
git checkout main
git pull origin main
git checkout -b hotfix/fix-critical-error
# Fix...
git add .
git commit -m "fix: correct authentication error"
# Send
git push -u origin hotfix/fix-critical-error
# Return to work
git checkout feature/login
git stash pop# "I deleted everything with reset --hard!"
git reflog
# HEAD@{1}: reset: moving to HEAD~5
# HEAD@{2}: commit: Implement important feature
# Recover
git reset --hard HEAD@{2}
# Everything back!# You have 10 messy commits
git log --oneline -10
# Organize with interactive rebase
git rebase -i HEAD~10
# In editor:
# pick -> keep commit
# squash -> merge with previous
# reword -> change message
# drop -> discard
# Force update branch
git push --force-with-leasegit merge main
# CONFLICT (content): Merge conflict in file.txt
# Open file.txt and see:
<<<<<<< HEAD
your branch code
=======
main code
>>>>>>> main
# Edit manually, remove markers
# Choose what to keep
git add file.txt
git commit -m "Resolve merge conflict"Detailed examples of real scenarios:
- Resolve Conflicts - Complete step by step
- Create Pull Request - Complete workflow
- Undo Commits - All techniques
main (always deployable)
├─ feature/login
├─ feature/payment
└─ hotfix/critical-bug
Rules:
mainalways working- Branch per feature
- Pull Request to review
- Merge and deploy
main (production)
└─ develop (development)
├─ feature/new-feature
├─ release/v1.2.0
└─ hotfix/correction
Branches:
main: production codedevelop: next versionfeature/*: new featuresrelease/*: release preparationhotfix/*: urgent fixes
main (trunk)
├─ feature-flags
└─ direct commits
Characteristics:
- Direct commits to main
- Short-lived branches (<1 day)
- Feature flags for incomplete features
- Robust CI/CD
Conventional Commits:
type(scope): short description
Detailed description (optional)
BREAKING CHANGE: description (optional)
Types:
feat: new featurefix: bug fixdocs: documentationstyle: formattingrefactor: refactoringtest: testschore: maintenance
Example:
git commit -m "feat(auth): add JWT authentication
Implement login with JWT tokens
Add authentication middleware
Tokens expire after 24h"Never commit:
- Passwords, API keys, tokens
- Environment files (
.env) - Dependencies (
node_modules/,venv/) - Build files (
dist/,build/) - IDE files (
.idea/,.vscode/) - Logs and temporary files
Use .gitignore:
# .gitignore
.env
node_modules/
*.log
.DS_StoreCommit when:
- Complete and tested functionality
- Bug fixed and verified
- Refactoring that doesn't break anything
- Updated documentation
Ideal size:
- Not too large (makes review difficult)
- Not too small (clutters history)
- One complete logical change
For quick visual reference, see:
docs/cheatsheet.md - Diagrams and organized commands
- Git Documentation - Complete documentation
- Pro Git Book - Free book
- Learn Git Branching - Visual and interactive
- Git Visualizer - Visualize commands
- GitKraken - Visual Git client
- SourceTree - Free client
- Git Extensions - For Windows
# You're not in a Git repository
git init # To create new
# OR
cd /path/to/repository # Go to existing repository# Your repository is outdated
git pull origin main# There are merge conflicts
git status # See conflicting files
# Edit files manually
git add <resolved-file>
git commit# Configure SSH keys
ssh-keygen -t ed25519 -C "your@email.com"
# Add key to GitHub
cat ~/.ssh/id_ed25519.pubgit log # Copy commit hash
git checkout correct-branch
git cherry-pick <hash>
git checkout wrong-branch
git reset --hard HEAD~1# Uncommitted local changes
git restore .
# Last commit (keep changes)
git reset --soft HEAD~1
# Last commit (discard changes)
git reset --hard HEAD~1
# If already pushed
git revert HEAD-
Practice basic commands
- Create test repository
- Make commits
- Create branches
-
Use interactive tools
- Run
git-learn.shto learn - Use
git-cli.shdaily - Test with
git-simulator.sh
- Run
-
Work on real project
- Contribute to open source
- Use Git in your projects
- Collaborate with others
-
Study advanced cases
- Interactive rebase
- Cherry-pick
- Bisect for debugging
-
Configure your environment
- Useful aliases
- Visual tools
- IDE integration
This is an open learning project. Contributions are welcome!
See CONTRIBUTING.md for details.
Since Git is infinite and many things are similar to each other, I definitely don't know everything. So, if anyone finds any error or has suggestions, feel free to open an issue and I'll fix it promptly. I even promise to buy you a chocolate as a reward for your contribution!
-
Go to the repository on GitHub
- Navigate to: https://github.com/madsondeluna/howtogit-1
-
Click on the "Issues" tab
- Located at the top of the repository page
-
Click the green "New issue" button
-
Fill in the issue details:
- Title: Write a clear, concise title describing the problem or suggestion
- Description: Provide details about:
- What's wrong or what could be improved
- Where you found the error (which file, section, or command)
- Any screenshots if applicable
- Your suggestions for improvement
-
Submit: Click "Submit new issue"
Example issue titles:
- "Error in git rebase command example"
- "Suggestion: Add section about git worktree"
- "Typo in Portuguese version - Módulo 2"
MIT License - see LICENSE for details.
Madson Aragão
Created to help developers master Git in a practical and accessible way.
Last updated: 2025-11-05
Course version: 2.0
This playlist is curated for deep work and focused coding sessions, ideal for maintaining concentration while preparing commits. Listen on Spotify
Bem-vindo ao curso completo de Git! Aprenda desde o básico até técnicas avançadas, com teoria, prática e ferramentas interativas.
O que torna este curso especial:
- Conteúdo Bilíngue: Todos os materiais, scripts e ferramentas CLI disponíveis em inglês e português
- Aprendizado Interativo: Ferramentas CLI práticas para praticar comandos Git com segurança
- Foco no Mundo Real: Exemplos práticos e casos de uso de workflows reais de desenvolvimento
- Aprendizado Progressivo: Do básico ao avançado, com progressão clara
- Código Aberto: Gratuito e aberto a contribuições
Todas as ferramentas CLI de aprendizado não supervisionado são bilíngues!
Git é um sistema de controle de versão distribuído criado por Linus Torvalds em 2005. Ele permite que você:
- Rastreie todas as mudanças feitas nos seus arquivos ao longo do tempo
- Trabalhe em diferentes versões do seu projeto simultaneamente (branches)
- Colabore com outras pessoas sem sobrescrever o trabalho delas
- Volte para qualquer versão anterior do seu código a qualquer momento
Analogia: Pense no Git como uma "máquina do tempo" para seus arquivos. Você pode:
- Ver o que mudou e quando
- Voltar para qualquer ponto no passado
- Criar realidades alternativas (branches) para testar ideias
- Mesclar diferentes linhas do tempo (merge)
Git NÃO é:
- Um serviço de nuvem (isso é GitHub, GitLab, etc.)
- Apenas para programadores (pode ser usado para qualquer arquivo de texto)
- Complicado (com prática se torna natural)
GitHub é uma plataforma web que hospeda repositórios Git na nuvem. É como uma "rede social para código".
Diferenças principais:
| Git | GitHub |
|---|---|
| Sistema de controle de versão | Plataforma de hospedagem |
| Funciona localmente no seu computador | Funciona na nuvem (online) |
| Software de linha de comando | Interface web + ferramentas |
| Gratuito e open source | Gratuito com recursos pagos |
| Criado em 2005 | Criado em 2008 |
O que o GitHub adiciona ao Git:
- Armazenamento remoto (backup na nuvem)
- Interface visual para revisar código
- Pull Requests (revisão de código colaborativa)
- Issues (gerenciamento de tarefas)
- Actions (automação de tarefas)
- Pages (hospedagem de sites estáticos)
- Colaboração social (seguir desenvolvedores, estrelar projetos)
Alternativas ao GitHub:
- GitLab
- Bitbucket
- Gitea
- SourceForge
Problemas sem controle de versão:
- "Onde está a versão que funcionava?"
- "Quem fez essa mudança e por quê?"
- "Como mesclo meu trabalho com o do meu colega?"
- "Perdi tudo! Não tenho backup!"
- Pastas cheias de:
projeto_v1,projeto_v2_final,projeto_v2_final_AGORA_VAI,projeto_final_final
Benefícios do Git:
- Histórico completo: Toda mudança é registrada com data, autor e motivo
- Trabalho paralelo: Múltiplas pessoas trabalhando simultaneamente sem conflitos
- Segurança: Backup distribuído - cada clone é um backup completo
- Experimentação segura: Teste ideias sem medo de quebrar o que funciona
- Rastreabilidade: Descubra quando e por que cada linha foi modificada
- Reversibilidade: Desfaça erros facilmente
- Colaboração: Trabalhe em equipe de forma organizada
- Profissionalismo: Padrão da indústria de software
Casos de uso:
- Desenvolvimento de software (principal)
- Documentação técnica
- Configurações de sistema
- Artigos e livros (texto)
- Trabalhos acadêmicos
- Qualquer projeto com múltiplas versões
Fluxo de trabalho de como o GitHub funciona
Fluxo básico de trabalho com GitHub (ou deveria se os usuários usassem da forma correta)
Repositório (Repository):
- Pasta que contém seu projeto e todo o histórico Git
- Pode ser local (no seu computador) ou remoto (GitHub, etc.)
Commit:
- Um "snapshot" (foto) do seu projeto em um momento específico
- Cada commit tem: hash único, autor, data, mensagem descritiva
Branch:
- Uma linha de desenvolvimento independente
- Permite trabalhar em features sem afetar o código principal
- Branch padrão:
main(oumasterem projetos antigos)
Merge:
- Combinar mudanças de uma branch em outra
- Pode gerar conflitos que precisam ser resolvidos manualmente
Working Directory:
- Os arquivos que você vê e edita na sua pasta
Staging Area (Index):
- Área intermediária onde você prepara arquivos para commit
- Permite fazer commits seletivos (só alguns arquivos)
Remote:
- Versão do repositório hospedada em outro lugar (GitHub, etc.)
- Nome padrão:
origin
Estados de um arquivo:
- Untracked: Git não está rastreando este arquivo
- Unmodified: Arquivo rastreado, sem mudanças desde último commit
- Modified: Arquivo foi modificado mas não está no staging
- Staged: Arquivo pronto para ser commitado
Para quem: Iniciantes que nunca usaram Git
Você vai aprender: Criar repositório, fazer commits, ver histórico
| Comando | Descrição |
|---|---|
git config --global user.name "Seu Nome" |
Define seu nome para todos os repositórios |
git config --global user.email "seu@email.com" |
Define seu email para todos os repositórios |
git config --list |
Mostra todas as configurações |
git --version |
Mostra a versão do Git instalada |
Exemplo:
git config --global user.name "Madson Aragão"
git config --global user.email "madson@example.com"
git config --global core.editor "vim"| Comando | Descrição |
|---|---|
git init |
Cria um novo repositório Git na pasta atual |
git clone <url> |
Copia um repositório remoto para seu computador |
Exemplo:
# Criar novo projeto
mkdir meu-projeto
cd meu-projeto
git init
# Clonar projeto existente
git clone https://github.com/usuario/repositorio.git| Comando | Descrição |
|---|---|
git status |
Mostra estado atual dos arquivos |
git status -s |
Status resumido (formato curto) |
git diff |
Mostra mudanças não staged |
git diff --staged |
Mostra mudanças staged |
Exemplo:
git status # Ver o que mudou
git diff arquivo.txt # Ver mudanças específicas| Comando | Descrição |
|---|---|
git add <arquivo> |
Adiciona arquivo específico ao staging |
git add . |
Adiciona todos os arquivos modificados |
git add -A |
Adiciona todos (incluindo deletados) |
git commit -m "mensagem" |
Cria commit com mensagem |
git commit -am "mensagem" |
Add + commit (só arquivos rastreados) |
Exemplo:
# Workflow básico
git add arquivo.txt
git commit -m "Adiciona novo arquivo"
# Ou tudo de uma vez
git add .
git commit -m "Atualiza documentação"| Comando | Descrição |
|---|---|
git log |
Mostra histórico completo de commits |
git log --oneline |
Histórico resumido (1 linha por commit) |
git log --graph |
Histórico com gráfico visual |
git log -n 5 |
Mostra últimos 5 commits |
git show <hash> |
Mostra detalhes de um commit específico |
Exemplo:
git log --oneline --graph --all
git log --author="Madson"
git log --since="2 weeks ago"| Comando | Descrição |
|---|---|
git remote add origin <url> |
Conecta repositório local ao remoto |
git remote -v |
Lista remotos configurados |
git push -u origin main |
Envia commits para remoto (primeira vez) |
git push |
Envia commits para remoto |
git pull |
Busca e mescla mudanças do remoto |
Exemplo:
# Conectar ao GitHub
git remote add origin https://github.com/usuario/repo.git
git push -u origin main
# Depois é só
git push
git pullPara quem: Quem já sabe o básico e quer trabalhar com branches e colaboração
| Comando | Descrição |
|---|---|
git branch |
Lista todas as branches locais |
git branch -a |
Lista todas as branches (local + remoto) |
git branch <nome> |
Cria nova branch |
git checkout <nome> |
Muda para outra branch |
git checkout -b <nome> |
Cria e muda para nova branch |
git switch <nome> |
Muda de branch (comando moderno) |
git branch -d <nome> |
Deleta branch (se já foi merged) |
git branch -D <nome> |
Força deleção de branch |
Exemplo:
# Criar feature
git checkout -b feature/login
# ... trabalhar ...
git add .
git commit -m "Implementa login"
# Voltar para main
git checkout main| Comando | Descrição |
|---|---|
git merge <branch> |
Mescla branch especificada na atual |
git merge --abort |
Cancela merge em andamento |
git merge --no-ff <branch> |
Merge sem fast-forward (cria commit de merge) |
Exemplo:
git checkout main
git merge feature/login
# Se houver conflitos
# 1. Edite os arquivos manualmente
# 2. Remova os marcadores de conflito
# 3. git add <arquivo-resolvido>
# 4. git commit| Comando | Descrição |
|---|---|
git stash |
Salva mudanças temporariamente |
git stash push -m "mensagem" |
Stash com mensagem descritiva |
git stash list |
Lista todos os stashes |
git stash pop |
Recupera último stash e remove da lista |
git stash apply |
Aplica stash mas mantém na lista |
git stash drop |
Remove último stash |
git stash clear |
Remove todos os stashes |
Exemplo:
# Mudança de contexto rápida
git stash push -m "WIP: trabalhando no login"
git checkout hotfix
# ... corrige bug urgente ...
git checkout feature/login
git stash pop| Comando | Descrição |
|---|---|
git restore <arquivo> |
Descarta mudanças em arquivo |
git restore --staged <arquivo> |
Remove arquivo do staging |
git reset --soft HEAD~1 |
Desfaz commit, mantém mudanças staged |
git reset --mixed HEAD~1 |
Desfaz commit, remove do staging |
git reset --hard HEAD~1 |
Desfaz commit e descarta mudanças |
git revert <hash> |
Cria novo commit desfazendo outro |
Exemplo:
# Desfazer mudanças locais
git restore arquivo.txt
# Desfazer último commit (mantém mudanças)
git reset --soft HEAD~1
# Desfazer commit específico (seguro para compartilhado)
git revert a1b2c3d| Comando | Descrição |
|---|---|
git tag |
Lista todas as tags |
git tag v1.0.0 |
Cria tag leve |
git tag -a v1.0.0 -m "Versão 1.0" |
Cria tag anotada |
git push origin v1.0.0 |
Envia tag para remoto |
git push origin --tags |
Envia todas as tags |
Exemplo:
git tag -a v1.0.0 -m "Primeira versão estável"
git push origin v1.0.0Para quem: Desenvolvedores experientes que querem dominar Git
| Comando | Descrição |
|---|---|
git rebase main |
Reaplica commits da branch atual sobre main |
git rebase -i HEAD~3 |
Rebase interativo (editar últimos 3 commits) |
git rebase --continue |
Continua rebase após resolver conflitos |
git rebase --abort |
Cancela rebase em andamento |
git pull --rebase |
Pull com rebase em vez de merge |
Quando usar:
- Manter histórico linear e limpo
- Antes de criar Pull Request
- Atualizar feature branch com main
CUIDADO: Não faça rebase de commits já enviados ao remoto!
Exemplo:
git checkout feature/login
git rebase main
# Limpar histórico antes de PR
git rebase -i HEAD~5
# No editor: squash, reword, drop| Comando | Descrição |
|---|---|
git cherry-pick <hash> |
Aplica commit específico na branch atual |
git cherry-pick <hash1> <hash2> |
Aplica múltiplos commits |
git cherry-pick --continue |
Continua após resolver conflitos |
git cherry-pick --abort |
Cancela cherry-pick |
Exemplo:
# Levar bugfix de uma branch para outra
git checkout main
git cherry-pick a1b2c3d| Comando | Descrição |
|---|---|
git reflog |
Mostra histórico de movimentos do HEAD |
git reflog show <branch> |
Reflog de branch específica |
git reset --hard <hash> |
Volta para commit específico do reflog |
Exemplo:
# "Perdi" commits após reset
git reflog
# HEAD@{2}: commit: Implementa feature X
git reset --hard HEAD@{2} # Recupera!| Comando | Descrição |
|---|---|
git bisect start |
Inicia busca binária por bug |
git bisect bad |
Marca commit atual como ruim |
git bisect good <hash> |
Marca commit como bom |
git bisect reset |
Finaliza bisect |
Exemplo:
git bisect start
git bisect bad # Commit atual tem bug
git bisect good v1.0.0 # v1.0.0 funcionava
# Git vai testando commits no meio
# Para cada um você testa e marca: git bisect good/bad| Comando | Descrição |
|---|---|
git blame <arquivo> |
Mostra quem modificou cada linha |
git blame -L 10,20 <arquivo> |
Blame de linhas específicas |
git blame -C <arquivo> |
Detecta linhas copiadas |
Exemplo:
git blame src/main.py -L 50,60| Comando | Descrição |
|---|---|
git submodule add <url> <path> |
Adiciona repositório como submódulo |
git submodule init |
Inicializa submódulos |
git submodule update |
Atualiza submódulos |
git clone --recursive <url> |
Clone com submódulos |
| Comando | Descrição |
|---|---|
git worktree add <path> <branch> |
Cria diretório para branch |
git worktree list |
Lista worktrees |
git worktree remove <path> |
Remove worktree |
Exemplo:
# Trabalhar em 2 branches simultaneamente
git worktree add ../projeto-feature feature/nova
cd ../projeto-feature
# Agora você tem 2 diretórios independentes!Arquivos em .git/hooks/:
pre-commit: Executa antes de commitpre-push: Executa antes de pushpost-merge: Executa após merge
Exemplo:
# .git/hooks/pre-commit
#!/bin/bash
npm test # Roda testes antes de permitir commitEste curso inclui ferramentas CLI interativas para facilitar o aprendizado e uso do Git.
git-learn.sh - Aprenda Git do zero
./scripts/git-learn.shConteúdo:
- 12 lições progressivas (básico ao intermediário)
- Explicações em português e inglês
- Exercício prático guiado ao final
- Cria repositório de teste real
Para quem:
- Iniciantes totais em Git
- Quem quer entender os conceitos
- Estudantes aprendendo programação
git-cli.sh - Execute comandos Git via menu
./scripts/git-cli.shFuncionalidades:
- 13 operações Git mais comuns
- Interface com menu numerado
- Confirmação para ações perigosas
- Detecta repositório automaticamente
- Mostra branch atual
Para quem:
- Quem quer agilizar tarefas comuns
- Iniciantes que ainda não decoraram comandos
- Uso rápido no dia a dia
git-simulator.sh - Simule operações Git sem risco
./scripts/git-simulator.shFuncionalidades:
- Cria ambiente de teste temporário
- Simula workflow completo de Git
- Visualiza estado do repositório
- Pratica sem medo de errar
- Ambiente é destruído ao sair
Para quem:
- Quem quer praticar sem risco
- Aulas e workshops de Git
- Testar comandos antes de usar em projetos reais
list-of-comds-how2git.sh - Comandos organizados e comentados
cat scripts/list-of-comds-how2git.sh
# ou
vim scripts/list-of-comds-how2git.shPara quem:
- Referência rápida
- Copiar e colar comandos
- Estudar sintaxe
# Clonar repositório
git clone https://github.com/empresa/projeto.git
cd projeto
# Ver estrutura de branches
git branch -a
# Ver últimos commits
git log --oneline -10
# Criar sua branch de trabalho
git checkout -b feature/minha-tarefa# Criar branch
git checkout -b feature/login
# Trabalhar...
git add .
git commit -m "feat: adiciona tela de login"
# Mais trabalho...
git commit -am "feat: adiciona validação"
# Atualizar com main
git fetch origin
git rebase origin/main
# Enviar para revisão
git push -u origin feature/login
# Criar Pull Request no GitHub# Salvar trabalho atual
git stash push -m "WIP: feature login"
# Criar hotfix
git checkout main
git pull origin main
git checkout -b hotfix/corrige-erro-critico
# Corrigir...
git add .
git commit -m "fix: corrige erro na autenticação"
# Enviar
git push -u origin hotfix/corrige-erro-critico
# Voltar ao trabalho
git checkout feature/login
git stash pop# "Deletei tudo com reset --hard!"
git reflog
# HEAD@{1}: reset: moving to HEAD~5
# HEAD@{2}: commit: Implementa feature importante
# Recuperar
git reset --hard HEAD@{2}
# Tudo de volta!# Você tem 10 commits bagunçados
git log --oneline -10
# Organizar com rebase interativo
git rebase -i HEAD~10
# No editor:
# pick -> manter commit
# squash -> mesclar com anterior
# reword -> mudar mensagem
# drop -> descartar
# Forçar atualização da branch
git push --force-with-leasegit merge main
# CONFLICT (content): Merge conflict in arquivo.txt
# Abrir arquivo.txt e ver:
<<<<<<< HEAD
código da sua branch
=======
código da main
>>>>>>> main
# Editar manualmente, remover marcadores
# Escolher o que manter
git add arquivo.txt
git commit -m "Resolve conflito de merge"Exemplos detalhados de cenários reais:
- Resolver Conflitos - Passo a passo completo
- Criar Pull Request - Workflow completo
- Desfazer Commits - Todas as técnicas
main (sempre deployável)
├─ feature/login
├─ feature/pagamento
└─ hotfix/bug-critico
Regras:
mainsempre funcionando- Branch por feature
- Pull Request para revisar
- Merge e deploy
main (produção)
└─ develop (desenvolvimento)
├─ feature/nova-feature
├─ release/v1.2.0
└─ hotfix/correcao
Branches:
main: código em produçãodevelop: próxima versãofeature/*: novas funcionalidadesrelease/*: preparação para releasehotfix/*: correções urgentes
main (trunk)
├─ feature-flags
└─ commits diretos
Características:
- Commits diretos em main
- Branches de vida curta (<1 dia)
- Feature flags para funcionalidades incompletas
- CI/CD robusto
Conventional Commits:
tipo(escopo): descrição curta
Descrição detalhada (opcional)
BREAKING CHANGE: descrição (opcional)
Tipos:
feat: nova funcionalidadefix: correção de bugdocs: documentaçãostyle: formataçãorefactor: refatoraçãotest: testeschore: manutenção
Exemplo:
git commit -m "feat(auth): adiciona autenticação JWT
Implementa login com tokens JWT
Adiciona middleware de autenticação
Expira tokens após 24h"Nunca commite:
- Senhas, API keys, tokens
- Arquivos de ambiente (
.env) - Dependências (
node_modules/,venv/) - Arquivos de build (
dist/,build/) - Arquivos do IDE (
.idea/,.vscode/) - Logs e temporários
Use .gitignore:
# .gitignore
.env
node_modules/
*.log
.DS_StoreFaça commit quando:
- Funcionalidade completa e testada
- Bug corrigido e verificado
- Refatoração que não quebra nada
- Documentação atualizada
Tamanho ideal:
- Nem muito grande (dificulta revisão)
- Nem muito pequeno (polui histórico)
- Uma mudança lógica completa
Para referência rápida visual, veja:
docs/cheatsheet.md - Diagramas e comandos organizados
- Git Documentation - Documentação completa
- Pro Git Book - Livro gratuito
- Learn Git Branching - Visual e interativo
- Git Visualizer - Visualize comandos
- GitKraken - Cliente Git visual
- SourceTree - Cliente gratuito
- Git Extensions - Para Windows
# Você não está em um repositório Git
git init # Para criar novo
# OU
cd /caminho/para/repositorio # Ir para repositório existente# Seu repositório está desatualizado
git pull origin main# Há conflitos de merge
git status # Ver arquivos conflitantes
# Editar arquivos manualmente
git add <arquivo-resolvido>
git commit# Configure SSH keys
ssh-keygen -t ed25519 -C "seu@email.com"
# Adicione a chave ao GitHub
cat ~/.ssh/id_ed25519.pubgit log # Copie hash do commit
git checkout branch-correta
git cherry-pick <hash>
git checkout branch-errada
git reset --hard HEAD~1# Mudanças locais não commitadas
git restore .
# Último commit (mantém mudanças)
git reset --soft HEAD~1
# Último commit (descarta mudanças)
git reset --hard HEAD~1
# Se já deu push
git revert HEAD-
Pratique os comandos básicos
- Crie repositório de teste
- Faça commits
- Crie branches
-
Use as ferramentas interativas
- Execute
git-learn.shpara aprender - Use
git-cli.shno dia a dia - Teste com
git-simulator.sh
- Execute
-
Trabalhe em projeto real
- Contribua para open source
- Use Git em seus projetos
- Colabore com outras pessoas
-
Estude casos avançados
- Rebase interativo
- Cherry-pick
- Bisect para debug
-
Configure seu ambiente
- Aliases úteis
- Ferramentas visuais
- Integração com IDE
Este é um projeto de aprendizado aberto. Contribuições são bem-vindas!
Veja CONTRIBUTING.md para detalhes.
Como Git é infinito e muita coisa é parecida uma com a outra, definitivamente não sei tudo, logo, se alguém encontrar algum erro ou tiver sugestões, pode abrir uma issue que corrijo prontamente. Prometo até pagar um chocolate como recompensa pela contribuição.
-
Vá até o repositório no GitHub
- Navegue até: https://github.com/madsondeluna/howtogit-1
-
Clique na aba "Issues"
- Localizada no topo da página do repositório
-
Clique no botão verde "New issue"
-
Preencha os detalhes da issue:
- Título: Escreva um título claro e conciso descrevendo o problema ou sugestão
- Descrição: Forneça detalhes sobre:
- O que está errado ou o que pode ser melhorado
- Onde você encontrou o erro (qual arquivo, seção ou comando)
- Screenshots se aplicável
- Suas sugestões de melhoria
-
Enviar: Clique em "Submit new issue"
Exemplos de títulos de issue:
- "Erro no exemplo do comando git rebase"
- "Sugestão: Adicionar seção sobre git worktree"
- "Erro de digitação na versão em português - Módulo 2"
MIT License - veja LICENSE para detalhes.
Madson Aragão
Criado para ajudar desenvolvedores a dominar Git de forma prática e acessível.
Última atualização: 2025-11-05
Versão do curso: 2.0
Esta playlist é selecionada para deep work e sessões de codificação, ideal para manter a concentração ao preparar commits. Ouça no Spotify



