introduzione a git
DESCRIPTION
Presentazione su Git tenuta all'incontro del PHP Users Group Friuli il 27/06/2012TRANSCRIPT
![Page 1: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/1.jpg)
Introduzione a GIT Il sistema di Source Control distribuito
PHP User Group Friuli, 27/06/2012
![Page 2: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/2.jpg)
STEFANO VALLE
![Page 3: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/3.jpg)
http://www.mvassociati.it/
![Page 4: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/4.jpg)
http://friuli.grusp.org/
![Page 5: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/5.jpg)
Chi usa GIT?
5
![Page 6: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/6.jpg)
COME SIAMO ARRIVATI A GIT?
![Page 7: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/7.jpg)
7
![Page 8: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/8.jpg)
8
CVS >> SVN
![Page 9: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/9.jpg)
![Page 10: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/10.jpg)
10
SVN >> GIT
![Page 11: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/11.jpg)
Perché è diverso?
11
![Page 12: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/12.jpg)
E’ MOLTO VELOCE
![Page 13: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/13.jpg)
E’ Distribuito
Pro Git - http://git-scm.com/book
![Page 14: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/14.jpg)
PERMETTE DI LAVORARE OFFLINE
![Page 15: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/15.jpg)
Incoraggia sviluppo non lineare
Pro Git - http://git-scm.com/book
![Page 16: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/16.jpg)
Come funzionano gli altri?
16
Pro Git - http://git-scm.com/book
![Page 17: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/17.jpg)
Come funziona GIT?
17
Pro Git - http://git-scm.com/book
![Page 18: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/18.jpg)
LE BASI
![Page 19: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/19.jpg)
Installare Git • Debian/Ubuntu
apt-get install git-core
• RedHat/Fedora/CentOS yum install git
• Disponibile per altre distribuzioni e SO:
http://git-scm.com/downloads
19
![Page 20: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/20.jpg)
Configurare Git • Identità:
git config --global user.name "John Doe"
git config --global user.email [email protected]
• Editor:
git config --global core.editor emacs
• Verifica parametri: git config --list
20
![Page 21: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/21.jpg)
«helper» per la console
21
![Page 22: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/22.jpg)
Disponibili anche GUI
22
![Page 23: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/23.jpg)
PARTIAMO!
![Page 24: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/24.jpg)
init
• Inizializza un nuovo repository all’interno della cartella corrente
• Crea la sottocartella .git che conterrà tutti i file ad uso interno di git
24
![Page 25: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/25.jpg)
clone
• Clona un repository git esistente
25
![Page 26: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/26.jpg)
add
• Aggiunge un nuovo file a git, che da quel momento ne terrà traccia
• Aggiunge un file modificato all’area di staging (che vediamo fra poco)
26
![Page 27: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/27.jpg)
commit
• Memorizza lo snapshot delle modifiche fatte
• Obbligatorio inserire un messaggio • Identificato da hash SHA-1
27
![Page 28: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/28.jpg)
Struttura di un commit
28
![Page 29: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/29.jpg)
Ciclo di vita di un file
29
Non gestito Non
modificato Modificato In stage
aggiunta del file
modifica del file
staging del file
rimozione del file
commit
![Page 30: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/30.jpg)
status
• Mostra lo stato in cui si trovano i file del repository
30
![Page 31: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/31.jpg)
log
• Mostra la storia dei commit • Per ciascuno elenca autore e messaggio
31
![Page 32: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/32.jpg)
DEMO 1
![Page 33: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/33.jpg)
branch
• La killer feature di GIT! • Consente di continuare lo sviluppo su una
nuova feature senza impattare sul lavoro corrente
33
![Page 34: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/34.jpg)
Un po’ di internals
34
Pro Git - http://git-scm.com/book
![Page 35: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/35.jpg)
git branch testing
35
Pro Git - http://git-scm.com/book
![Page 36: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/36.jpg)
Su quale branch stiamo lavorando?
36
Pro Git - http://git-scm.com/book
![Page 37: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/37.jpg)
checkout
• Consente di passare da un branch all’altro • (o anche da un commit all’altro)
37
![Page 38: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/38.jpg)
git checkout testing
38
Pro Git - http://git-scm.com/book
![Page 39: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/39.jpg)
DEMO 2 - BRANCHING
![Page 40: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/40.jpg)
merge
• Incorpora sul branch principale le modifiche fatte su un altro branch
• Assieme a branch, è un altro comando che git incentiva ad usare spesso
40
![Page 41: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/41.jpg)
merge
41
fast-forward
Pro Git - http://git-scm.com/book
![Page 42: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/42.jpg)
merge
42
Non fast-forward
Pro Git - http://git-scm.com/book
![Page 43: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/43.jpg)
DEMO 2 – OPERAZIONI DI MERGE
![Page 44: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/44.jpg)
L’IMPREVISTO: I CONFLITTI
![Page 45: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/45.jpg)
rebase
• Altro modo per integrare le modifiche di un branch
• Prende linearmente tutte le modifiche fatte su un branch e le applica ad un altro
45
![Page 46: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/46.jpg)
rebase
46
Pro Git - http://git-scm.com/book
![Page 47: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/47.jpg)
Merge Prende gli ultimi commit e li «mette assieme», creando un nuovo commit di merge
Rebase Applica le modifiche di un branch linearmente su un nuovo branch
47
Pro Git - http://git-scm.com/book
![Page 48: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/48.jpg)
Git distribuito
48
repository condiviso
sviluppatore 1 sviluppatore 2 sviluppatore 3
![Page 49: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/49.jpg)
remote
• Consente di gestire repository remoti • Sincronizzandoli con il proprio repo locale
49
![Page 50: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/50.jpg)
fetch
• Scarica branch e dati da un repository remoto
50
![Page 51: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/51.jpg)
pull
• Scarica dati da un repository remoto e tenta di fare il merge con il branch corrente
• pull = fetch + merge
51
![Page 52: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/52.jpg)
push
• Invia branch e dati ad un repository remoto
• Consente di aggiornare il repository remoto con le modifiche fatte localmente
52
![Page 53: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/53.jpg)
DEMO 3 - REBASE
![Page 54: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/54.jpg)
I REPOSITORY PUBBLICI
![Page 55: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/55.jpg)
Github
55
![Page 56: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/56.jpg)
Bitbucket
56
![Page 57: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/57.jpg)
DEMO 4 – GIT WORKFLOW
![Page 58: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/58.jpg)
Premessa • Usate git per qualsiasi progetto • Anche se sviluppate da soli • Anche se lavorate solo in locale
58
![Page 59: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/59.jpg)
Branches
59
![Page 60: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/60.jpg)
Long-running branches • master
– Allineato con versione on-line
• develop – Allineato con versione in sviluppo
60
![Page 61: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/61.jpg)
Topic branches • Branch in cui sviluppare feature • Feature terminata (e testata)? merge su
develop • Al termine, il branch viene cancellato
61
![Page 62: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/62.jpg)
Hotfix branches • Per bug fix / interventi veloci • Fix terminato, merge su develop • Cancellato al termine del merge • Ha una vita molto breve
62
![Page 63: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/63.jpg)
COMANDI UTILI
![Page 64: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/64.jpg)
diff
• Mostra le differenze introdotte dalle modifiche non committate
64
![Page 65: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/65.jpg)
tag
• Consente di contrassegnare un commit • Spesso usato per identificare le versioni
del progetto
65
![Page 66: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/66.jpg)
stash
• Salva temporaneamente il contenuto della working directory, ripulendola
• Consente di cambiare branch in qualsiasi momento
66
![Page 67: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/67.jpg)
reset
• Il comando più ambiguo! • Consente di:
– Togliere file dallo staging – Eliminare definitivamente file dallo staging – Riavvolgere storia commit
67
![Page 68: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/68.jpg)
revert
• Consente di annullare uno o più commit • Crea un nuovo commit che annulla
l’effetto dei commit da eliminare
68
![Page 69: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/69.jpg)
submodule
• Consente di includere un repository git all’interno del proprio progetto git
• Utile per caricare librerie esterne
69
![Page 70: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/70.jpg)
BEST PRACTICES
![Page 71: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/71.jpg)
Commit • Fare commit spesso • Un commit deve inglobare un insieme
atomico di modifiche • NON lavorare N giorni in attesa di aver
finito il task! • Al massimo fare tutti i commit alla fine,
sfruttando lo staging
71
![Page 72: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/72.jpg)
Testo del commit • Sommario da max 50 caratteri • Seguito (eventualmente) da descrizione
più dettagliata • Forma imperativa (es. «Add products
section», ...)
72
![Page 73: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/73.jpg)
COMMIT E PUSH PRIMA DEL COLLEGA!
![Page 74: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/74.jpg)
LAVORARE TUTTI SUL MASTER, HUH?
![Page 75: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/75.jpg)
TESTARE IL CODICE PRIMA DI COMMITTARLO
![Page 76: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/76.jpg)
Decidere un workflow
76
![Page 77: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/77.jpg)
LAVORARE CON GIT E’ PIACEVOLE
![Page 78: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/78.jpg)
Per approfondire:
• Pro git: http://git-scm.com/book
• http://gitref.org/ • http://gitready.com/
78
![Page 79: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/79.jpg)
DUBBI? DOMANDE?
![Page 80: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/80.jpg)
http://www.hubme.in/
![Page 82: Introduzione a Git](https://reader034.vdocuments.pub/reader034/viewer/2022042515/5484c3f75806b5a9588b46ba/html5/thumbnails/82.jpg)
Referenze Immagini • http://www.flickr.com/photos/boston_public_library/6323438849/ • http://www.flickr.com/photos/a03575/3632344397/
• http://www.flickr.com/photos/chiperoni/3456589962/ • http://www.flickr.com/photos/53370644@N06/4976492450 • http://www.flickr.com/photos/lululemonathletica/4911299076/ • http://www.flickr.com/photos/psi_mon/3473153641/
• http://www.flickr.com/photos/masstravel/7454482646/ • http://www.flickr.com/photos/53370644@N06/4976497160/ • http://www.flickr.com/photos/53370644@N06/4975888229/
• http://www.flickr.com/photos/53370644@N06/4976490816/
• http://www.flickr.com/photos/visualgrammar/2997271008/ • http://www.flickr.com/photos/ejcdelahoya/2504629292/ • http://www.flickr.com/photos/altuwa/3582839737 • http://www.flickr.com/photos/marine_corps/5132830788/
• http://www.flickr.com/photos/72213316@N00/5028110521/ • http://www.flickr.com/photos/stevengrayphotography/6893446706/