Verificar configurações gerais.
$ git config --list
Para trocar o login
$ git config --global user.name "seu usuário"
Para trocar o e-mail
$ git config --global user.email seuemail@example.com
Para salvar senhas:
$ git config --global credential.helper store
$ git push -u origin seu-branch
Remover todos os arquivos que foram add
no HEAD
$ git reset HEAD
Para retirar o arquivo file.txt
do HEAD
$ git reset HEAD file.txt
windows
$ git reset --soft HEAD~
Linux, Mac
$ git reset --soft HEAD^
$ git add seu-arquivo
$ git commit --amend --no-edit
Para atualizar seu repositório local com a mais nova versão
$ git pull
Adiciona o git repositório
$ git remote add upstream repositorio.git
O exemplo abaixo move os três últimos commits para newbranch
$ git branch newbranch
$ git reset --hard HEAD~3
$ git checkout newbranch
O exemplo abaixo move o commit C para o branch master, onde C é o hash do commit.
$ git checkout master
$ git merge C
Criar tag Anotada
$ git tag -a v1.4 -m 'my version 1.4'
Deletar tag (legal apenas quando não tiver publicado)
$ git tag -d v1
Subir tag para repositório
$ git push origin v1.5
Compara dois branchs
$ git diff branch_1..branch_2
Alterar repositório
$ git remote set-url origin http://repositorio
Visualizar repositório atual
$ git remote -v
Atualizar com repositório com o branch que escolher
$ git pull origin master
Caso esteja no master
irá unir todos os arquivos do 1-correcao-bug-menu
$ git merge 1-correcao-bug-menu
Mostra todos os branchs do local. Acrescente -v
e veja com commits
$ git branch
Remover branch local
$ git branch -d name-branch
Mostra todos os branchs do repositório. Acrescente -v
e veja com commits
$ git branch -r
Excluir um branch no repositório
$ git push origin :branch
Apesar do agrupamento por finalidade ser melhor do que o agrupamento por autor,
há como aumentar ainda mais a legibilidade do histórico, usando a opção
--no-ff
na hora de fazer o Merge:
$ git checkout feature/do-something
$ git rebase master
$ git checkout master
$ git merge --no-ff feature/do-something
Resolvendo conflitos de códigos
$ git checkout -b branch
$ git checkout master
$ git pull origin master
$ git checkout branch
$ git merge master
Quando fez a besteira de alterar arquivos no branch errado
$ git stash
$ git stash branch temporario
$ git checkout -b nova-consulta
$ git merge --no-ff temporario
$ git branch -d temporario
git log
de forma resumida
$ git log --oneline