As perguntas da entrevista do Git testam sua compreensão dos conceitos de controle de versão, estratégias de ramificação, mesclagem versus rebase e fluxos de trabalho colaborativos. Este guia cobre as perguntas mais comuns do Git para entrevistas com desenvolvedores de software em 2026.
Perguntas básicas do Git
1. Qual é a diferença entre git merge e git rebase?
# merge: combines two branches, preserves full history
git checkout feature
git merge main
# Creates a merge commit — shows when branches diverged
# rebase: moves/replays commits on top of another branch
git checkout feature
git rebase main
# Linear history — as if feature branched off current main
# When to use merge:
# - Integrating feature branches to main (preserves history)
# - Public/shared branches (never rebase!)
# - When you want to see branch history
# When to use rebase:
# - Keeping feature branch up to date with main
# - Cleaning up local commits before PR
# - Squashing minor fix commits
# Golden rule: never rebase commits that have been pushed to shared branches
2. O que é HEAD e o que é HEAD desanexado?
# HEAD = pointer to current commit (usually points to branch tip)
cat .git/HEAD # ref: refs/heads/main (pointing to main branch)
# Detached HEAD: HEAD points directly to a commit, not a branch
git checkout abc123 # checking out a specific commit
# HEAD is now at abc123 (detached)
# Any commits made won't belong to any branch!
# To save work in detached HEAD:
git checkout -b new-branch # create branch from current position
# Common cause: git checkout <tag> or git checkout <commit-hash>
3. Explique git reset vs git revert
# git reset: move HEAD backward (rewrites history)
git reset --soft HEAD~1 # undo commit, keep changes staged
git reset --mixed HEAD~1 # undo commit, keep changes unstaged (DEFAULT)
git reset --hard HEAD~1 # undo commit AND discard changes (DESTRUCTIVE)
# NEVER use --hard on shared branches!
# git revert: create a new commit that undoes a previous commit
git revert abc123 # safe for shared branches
# Creates commit: "Revert 'feature: add user auth'"
# Use reset for: local commits you want to undo
# Use revert for: commits already pushed to shared branches
4. O que é git stash e quando você o usa?
# Temporarily save uncommitted changes
git stash push -m "WIP: half-done feature"
git stash list # see all stashes
git stash pop # apply latest + remove
git stash apply stash@{0} # apply without removing
git stash drop stash@{0} # delete a stash
# Stash specific files
git stash push -m "CSS fix" -- styles.css components/Button.css
# Include untracked files
git stash push -u -m "including new files"
# Common workflow:
# 1. Working on feature-A
# 2. Urgent fix needed on feature-B
# git stash (save feature-A work)
# git checkout feature-B
# ... fix ...
# git checkout feature-A
# git stash pop (restore feature-A work)
5. Como você elimina vários commits?
# Interactive rebase — squash last 3 commits
git rebase -i HEAD~3
# Editor opens:
# pick abc123 feat: add login form
# pick def456 fix: correct validation
# pick ghi789 fix: typo in error message
# Change to:
# pick abc123 feat: add login form
# squash def456 fix: correct validation
# squash ghi789 fix: typo in error message
# Result: one clean commit with combined message
# Alternative: squash merge (GitHub/GitLab button)
# When merging PR, select "Squash and merge"
# All commits become one commit in main
6. O que é escolha seletiva?
# Apply a specific commit from another branch
git log --oneline feature-branch # find the commit hash
git cherry-pick abc123 # apply just that commit
# Common use: apply a hotfix to multiple release branches
git checkout release/2.0
git cherry-pick fix/critical-bug-abc123
git checkout release/1.9
git cherry-pick fix/critical-bug-abc123
# Cherry-pick a range
git cherry-pick abc123..def456 # applies all commits in range
# If conflicts arise
git cherry-pick --continue # after resolving conflicts
git cherry-pick --abort # cancel cherry-pick
7. Explique estratégias de ramificação
GitFlow (complex, stable releases):
main — production
develop — integration
feature/xxx — feature branches
release/1.0 — release preparation
hotfix/xxx — urgent fixes
GitHub Flow (simple, continuous delivery):
main — always deployable
feature/xxx — short-lived feature branches
Pull Request → Code Review → Merge to main → Deploy
Trunk-Based Development (very short-lived branches):
main (trunk) — everyone commits daily
feature/xxx — max 1-2 days old, use feature flags
2026 recommendation: GitHub Flow or Trunk-Based for most teams
8. O que é .gitignore e por que é importante?
# .gitignore tells git which files to ignore
# Never commit:
# - Secrets/credentials (.env files!)
# - Dependencies (node_modules/, vendor/)
# - Build artifacts (dist/, __pycache__/)
# - OS files (.DS_Store, Thumbs.db)
# - IDE files (.idea/, .vscode/ — optional)
# Example .gitignore
*.env
*.env.*
node_modules/
dist/
build/
.DS_Store
__pycache__/
*.pyc
*.pem
*.key
# Already committed? Remove from tracking:
git rm --cached .env # stop tracking but keep file
git rm -r --cached dist/ # stop tracking directory
# Global gitignore (applies to all repos)
git config --global core.excludesfile ~/.gitignore_global
Sucesso na entrevista do Git: entenda o modelo de histórico (commits, branchs, HEAD), saiba a diferença entre merge e rebase e quando usar cada um, explique claramente reset vs revert e demonstre conhecimento de fluxos de trabalho de equipe (GitHub Flow, GitFlow). Pratique em repositórios reais – ler o histórico do git é mais fácil do que descrevê-lo teoricamente.
🔗 Share this article
✍️ Leave a Comment