58
GIT

Conhecendo o GIT

Embed Size (px)

Citation preview

Page 1: Conhecendo o GIT

GIT

Page 2: Conhecendo o GIT

Controle de Versão

Centralizado • SVN

Distribuído • Mercurial

• GIT

Page 3: Conhecendo o GIT

GIT

• Criado por Linus Torvalds

• Sistema de snapshots

• Trabalho localmente

• Integridade(Hash SHA-1)

Page 4: Conhecendo o GIT

Instalação

Linux !

$ yum install git-core $ apt-get install git

Page 5: Conhecendo o GIT

Instalação

Windows !

http://msysgit.github.com

Page 6: Conhecendo o GIT

Instalação

Mac !

http://code.google.com/p/git-osx-installer !$ sudo port install git-core +svn +doc +bash_completion +gitweb

Page 7: Conhecendo o GIT

Configurações Básicas

Dados pessoais

$ git config --global user.name "John Doe"

$ git config --global user.email [email protected]

Page 8: Conhecendo o GIT

Configurações Básicas

Editores

$ git config --global core.editor "mate -wl1"

$ git config --global core.editor "vim"

$ git config --global core.editor "nano"

Page 9: Conhecendo o GIT

Configurações Básicas

Cores

$ git config --global core.diff "auto"

$ git config --global core.status "auto"

$ git config --global core.interactive "auto"

$ git config --global core.grep "auto"

$ git config --global core.branch "auto"

Page 10: Conhecendo o GIT

Configurações Básicas

Alias

$ git config --global alias.st "status"

$ git config --global alias.ci "commit"

$ git config --global alias.co "checkout"

$ git config --global alias.lg "log --oneline --decorate"

Page 11: Conhecendo o GIT

Configurações BásicasHelpers

$ git config --global --list //Listagem das configurações

$ git config --global core.autocrlf input //Git ajusta a quebra de linha

Page 12: Conhecendo o GIT

Estados

Page 13: Conhecendo o GIT

Comandos Básicos

• $ git init //Inicia o repositório git

• $ git add ( . || files) //Adiciona os arquivos no modo stage

• $ git rm ( . || files) //Remove o arquivo do git

• $ git status //Mostra os status dos arquivos no git

• $ git commit //Adiciona as alterações no git

• $ git diff //Mostra a diferença entre os arquivos

Page 14: Conhecendo o GIT

Comandos Básicos

• $ git clone (url || path) //Copiar um repositório

• $ git push //Enviar todos os commites para o repositório remoto

• $ git pull //Puxar todos os commites do repositórios remoto

• $ git log //Mostra todos os commits feitos

• $ git show //Mostra as alterações dentro de um commit

• .gitignore //Arquivo onde ignora alguns arquivos

Page 15: Conhecendo o GIT

GUI

Linux https://wiki.gnome.org/Apps/giggle

Mac http://www.git-tower.com/ http://mac.github.com/

Windows https://code.google.com/p/tortoisegit/

GITK !

GitGutter - Sublime

Page 16: Conhecendo o GIT

Remotes

!

$ git remote -v //Listagem de repositórios remotos

$ git remote add url //Adicionar link de repositórios remoto

$ git remote remover url //Remover referência de um repositórios

Page 17: Conhecendo o GIT

$ Git Reset $ git reset --soft HEAD ~1 //Voltar commit sem perder as alterações $ git reset --hard HEAD ~1

//Voltar commit e remove as alterações $ git reset ORIG_HEAD //Voltar o commit HEAD do origin

Page 18: Conhecendo o GIT

$ Git Revert$ git revert HEAD~1

//Refazer o commit anterior $ git revert HASH

//Refazer o commit especificando a hash

Page 19: Conhecendo o GIT

Branch$ git branch nome //Criar

$ git checkout -b nome //Criar e entrar $ git checkout -D nome //Remover local

$git push remote :branch //Remover remoto

Page 20: Conhecendo o GIT

Branch

Page 21: Conhecendo o GIT

Branch

$ git branch testing

Page 22: Conhecendo o GIT

Branch

Page 23: Conhecendo o GIT

Branch

$ git checkout testing

Page 24: Conhecendo o GIT

Branch

$ vim test.rb $ git commit -a -m 'Adicionar teste'

Page 25: Conhecendo o GIT

Branch $ git checkout master

Page 26: Conhecendo o GIT

Branch $ git checkout master

$ vim test.rb $ git commit -a -m 'Mais testes'

Page 27: Conhecendo o GIT

Merge$ git merge branch

Page 28: Conhecendo o GIT

Merge

Page 29: Conhecendo o GIT

Merge

$ git checkout -b iss53

Page 30: Conhecendo o GIT

Merge

$ git checkout -b iss53

$ git commit -a -m 'Novo footer'

Page 31: Conhecendo o GIT

Merge

$ git checkout master $ git checkout -b hotfix $ git commit -a -m 'Mudou o email'

Page 32: Conhecendo o GIT

Merge

$ git checkout master $ git checkout -b hotfix $ git commit -a -m 'Mudou o email'

$ git checkout master $ git merge hotfix

Page 33: Conhecendo o GIT

Merge$ git checkout iss53 $ git commit -a -m 'Novo Footer'

Page 34: Conhecendo o GIT

Merge$ git checkout iss53 $ git commit -a -m 'Novo Footer'

$ git checkout master $ git merge iss53

Page 35: Conhecendo o GIT

Merge Unificado$ git merge --squash branch

Page 36: Conhecendo o GIT

Rebase$ git rebase branch

Page 37: Conhecendo o GIT

Rebase

Page 38: Conhecendo o GIT

Rebase

$ git merge experiment

Page 39: Conhecendo o GIT

Rebase

Page 40: Conhecendo o GIT

Rebase$ git checkout experiment $ git rebase master

Page 41: Conhecendo o GIT

Rebase$ git checkout experiment $ git rebase master

Page 42: Conhecendo o GIT

Diff

$ git diff HASH > file.diff

Page 43: Conhecendo o GIT

Diff

$ git diff HASH > file.diff

$ git am file.diff

Page 44: Conhecendo o GIT

Conflito

<<<<<<< HEAD:index.html <div id="footer">contato : [email protected]</div> ======= <div id="footer"> por favor nos contate em [email protected] </div> >>>>>>> iss53:index.html

Page 45: Conhecendo o GIT

Conflito

<<<<<<< HEAD:index.html <div id="footer">contato : [email protected]</div> ======= <div id="footer"> por favor nos contate em [email protected] </div> >>>>>>> iss53:index.html

$ git mergetool

Page 46: Conhecendo o GIT

Stash$ git stash save //Salvar arquivos alterados no stash

$ git stash list //Listar todos os stashs $ git stash pop //Adicionar as alteração no workspace

$ git stash drop //Remove o stash

Page 47: Conhecendo o GIT

Tags$ git tag //Lista

$ git tag name HASH //Adicionar em um commit $ git tag -d name //Remove a tag

Page 48: Conhecendo o GIT

Sub Modulos$ git submodul add url path

$ git submodul init $ git submodul update

Page 49: Conhecendo o GIT

Git SVN$ git svn clone url

$ git svn fetch $ git svn dcommit $ git svn branch

Page 50: Conhecendo o GIT

Servers

Page 51: Conhecendo o GIT

Ferramentas GitHub

• Fork

• Issues

• Pull Requests

• Wiki

Page 52: Conhecendo o GIT

URL GitHub

[email protected]:Xhamps/expirience_html5.gitUsuário SSH

Server Repositório

Usuário

Page 53: Conhecendo o GIT

Server Local$ git init --bare

Page 54: Conhecendo o GIT

Hooks

Page 55: Conhecendo o GIT

Outros comandos

• $ git fetch //Puxar todas as atualizações sem dar um merge

• $ git ls-remote //Listar tags remotas

• $ git reflog //Mostrar todas alterações no git

• $ git blame //Lista quem alterou determinado arquivo

• $ git gc //Limpa todo o git

• $ git remote prune origin //Limpar referência de branch

Page 56: Conhecendo o GIT

Outros comandos

• $ git cherry -v branch //Mostrar todos os commits não enviados

• $ git cherry-pick hash //Adicionar só um commit de outro branch ao branch atual

• $ git update-index --assume-unchanged //Não trackear alterações de um arquivo

• $ git commit --amend // Refazer o último commit

• $ git checkout --orphan // Criar branch vazio

• $ git pull --rebase // Forçar rebase no envio

Page 57: Conhecendo o GIT

Workflow

http://danielkummer.github.io/git-flow-cheatsheet/index.pt_BR.html

Page 58: Conhecendo o GIT

Obrigado.

Referências

http://git-scm.com/book/pt-br

Imagens

http://octodex.github.com