Configuração Inicial
git config --global user.name "Seu Nome"
git config --global user.email "seu@email.com"
git config --list
Comandos Básicos
Inicializar e Clonar
git init
git clone <url>
git clone -b <branch> <url>
Mudanças e Commits
git status
git add <arquivo>
git add .
git commit -m "mensagem do commit"
git commit -am "mensagem"
Branches
git branch
git branch <nome>
git checkout <branch>
git checkout -b <nova-branch>
git branch -d <branch>
Merge e Rebase
git merge <branch>
git rebase <branch>
git add .
git rebase --continue
Remoto
git remote -v
git remote add origin <url>
git push origin <branch>
git pull origin <branch>
git fetch
Histórico
git log
git log --oneline
git log --graph --oneline
git show <commit>
Desfazer Mudanças
git checkout -- <arquivo>
git reset HEAD <arquivo>
git reset --soft HEAD~1
git reset --hard HEAD~1
Dicas Úteis
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git diff
git stash
git stash pop
Solução de Problemas
| Situação | Solução |
|---|
| Mensagem de commit errada | git commit --amend -m "nova mensagem" |
| Commit feito por engano | git reset --soft HEAD~1 para desfazer |
| Conflito de merge | Editar arquivos → git add → git commit |
| Push rejeitado | git pull --rebase depois push novamente |
| Restaurar arquivo específico | git checkout <commit> -- <arquivo> |
git checkout -b feature/autenticacao
git add . && git commit -m "feat: implementar autenticação"
git push -u origin feature/autenticacao
git checkout main && git pull
git branch -d feature/autenticacao
Artigos Relacionados
← Voltar para a lista