Principais Comandos Git Para o Dia a Dia


Aqui está um guia rápido com os comandos Git mais úteis para o cotidiano de qualquer desenvolvedor.
git config --global user.name "Seu Nome" git config --global user.email "seuemail@example.com" git config --global init.defaultBranch main
git init git clone https://github.com/usuario/repositorio.git
git status git diff
git add nome-do-arquivo git add . # adiciona tudo
git commit -m "Mensagem do commit" git commit -am "Add + commit (para arquivos já versionados)"
git pull git pull origin main
git push git push origin main
Criar nova branch:
git checkout -b nova-feature
Trocar de branch:
git checkout main
Listar branches:
git branch
Deletar branch local:
git branch -d nome-da-branch
Merge:
git merge nome-da-branch
Rebase:
git rebase main
Voltar arquivo modificado:
git checkout -- arquivo
Remover do stage:
git reset arquivo
Voltar commit mantendo alterações:
git reset --soft HEAD~1
Voltar commit descartando alterações:
git reset --hard HEAD~1
git stash git stash list git stash apply
git log git log --oneline --graph
Esses comandos cobrem 90% do dia a dia com Git.
Guarde esse guia para consultas rápidas e compartilhe com seus amigos.
Here is a quick guide with the most useful Git commands for any developer's daily routine.
git config --global user.name "Your Name" git config --global user.email "youremail@example.com" git config --global init.defaultBranch main
git init git clone https://github.com/user/repository.git
git status git diff
git add filename git add . # adds everything
git commit -m "Commit message" git commit -am "Add + commit (for already tracked files)"
git pull git pull origin main
git push git push origin main
Create new branch:
git checkout -b new-feature
Switch branch:
git checkout main
List branches:
git branch
Delete local branch:
git branch -d branch-name
Merge:
git merge branch-name
Rebase:
git rebase main
Revert modified file:
git checkout -- file
Remove from stage:
git reset file
Undo commit keeping changes:
git reset --soft HEAD~1
Undo commit discarding changes:
git reset --hard HEAD~1
git stash git stash list git stash apply
git log git log --oneline --graph
These commands cover 90% of daily Git usage. Keep this guide for quick reference and share it with your friends.