DEV Community

Vitor Jr.
Vitor Jr.

Posted on

Aprendendo Git Branching - Comandos

Comandos utilizados e aprendidos na série Aprendendo Git Branching.

Comandos

commit

# cria um snapshot do trabalho atual
git commit
Enter fullscreen mode Exit fullscreen mode

branch

# cria uma nova branch chamada newImage
git branch newImage
Enter fullscreen mode Exit fullscreen mode

checkout

# cria a nova branch bugFix e altera para a mesma
git checkout -b bugFix

# C1: hash do commit
# faz checkout e aponta o head para o commit C1
git checkout C1

# sendo que a branch bugFix está em C4:
# 1-fazer checkout para a branch bugFix
# 2-fazer checkout para o commit C3
git checkout bugFix^

# sendo que HEAD e a branch main está em C4:
# 1-fazer checkout para a branch main
# 2-fazer checkout para o commit C0
git checkout HEAD~4

# sendo que HEAD e a branch main está em C7:
# 1-fazer checkout para o segundo pai do commit C7
# 2-fazer checkout para dois commits atrás do segundo pai
git checkout HEAD~^2~2
Enter fullscreen mode Exit fullscreen mode

cherry-pick

# dados os commits C1, C2, C3, C4, C5, C6 e C7
# escolher apenas os commits C7, C3 e C5 nessa ordem
# para serem adicionados na branch main
git cherry-pick C7 C3 C5
Enter fullscreen mode Exit fullscreen mode

reset

# move a referêcia para o commit anterior repo LOCAL
git reset HEAD~1
Enter fullscreen mode Exit fullscreen mode

revert

# move a referêcia para o commit anterior repo REMOTO
git revert HEAD
Enter fullscreen mode Exit fullscreen mode

rebase

# tendo feito o checkout para branch bugFix
# move o trabalho dessa branch para a main
git rebase main

# tendo a branch main como HEAD
# selecionar opções dentro dos útimos 3 commits
git rebase -i HEAD~3
Enter fullscreen mode Exit fullscreen mode

merge


Enter fullscreen mode Exit fullscreen mode

tag

# cria uma tag para o commit C1 com o nome v1.0
git tag v1.0 C1
Enter fullscreen mode Exit fullscreen mode

fetch


Enter fullscreen mode Exit fullscreen mode

pull

# faz o pull e rebase ao mesmo tempo
git pull --rebase

Enter fullscreen mode Exit fullscreen mode

push


Enter fullscreen mode Exit fullscreen mode

Top comments (0)