Introducción a git y GitHub

133
git /' t/ ɡɪ @luke_ar @matitanio #charlagit uno21.com.ar

description

Diapositivas de la charla dada por la gente de uno21.com.ar (@luke_ar y @matitanio) en la UP, el día 21/08/2012. Próximamente en otras universidades :)

Transcript of Introducción a git y GitHub

Page 1: Introducción a git y GitHub

git/' t/ɡɪ

@luke_ar@matitanio#charlagit uno21.com.ar

Page 2: Introducción a git y GitHub

¿qué es git?

Page 3: Introducción a git y GitHub

¿qué es git?un scv

Page 4: Introducción a git y GitHub

un sistema de control deversiones es nuestro 

DeLorean personal quenos permitirá viajar por la

historia de un archivo ynos proveerá facilidades

para el trabajo en equipo

Page 5: Introducción a git y GitHub

branch

tag

working copy

tree

fork

check­in

check­out

update

change list

conflictheadlabel

merge

reporevision

trunk

commit

Page 6: Introducción a git y GitHub

¿qué es git?

Page 7: Introducción a git y GitHub

git es un sistema de controlde versiones distribuído de

código abierto diseñado parala velocidad y eficiencia

Page 8: Introducción a git y GitHub

git es un sistema de controlde versiones distribuido de

código abierto diseñado parala velocidad y eficiencia

Page 9: Introducción a git y GitHub

totalmente distribuido

Page 10: Introducción a git y GitHub
Page 11: Introducción a git y GitHub

(casi) todo es local

Page 12: Introducción a git y GitHub

lo que significa que

todo es rápido

cada repositorio es un backup

se puede trabajar off­line

Page 13: Introducción a git y GitHub

no se necesita red para

hacer un diff

ver el histórico

commitear cambios

mergear branches

obtener una revisión de un archivo

cambiar de branch

Page 14: Introducción a git y GitHub

git es un sistema de controlde versiones distribuído de

código abierto diseñado parala velocidad y eficiencia

Page 15: Introducción a git y GitHub

git­scm.com

Page 16: Introducción a git y GitHub

github.com/git/git

Page 17: Introducción a git y GitHub

git es un sistema de controlde versiones distribuido de

código abierto diseñado parala velocidad y eficiencia

Page 18: Introducción a git y GitHub

inmutable

Page 19: Introducción a git y GitHub

(casi) nunca se borran datos

Page 20: Introducción a git y GitHub

snapshots, no parches

Page 21: Introducción a git y GitHub

(eso lo dejamos para después)

Page 22: Introducción a git y GitHub

git local

Page 23: Introducción a git y GitHub

demo ㋡

Page 24: Introducción a git y GitHub

primeros pasos

Page 25: Introducción a git y GitHub

git config

$ git config --global user.name "Lucas Videla"

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

$ git config --global color.ui true

Page 26: Introducción a git y GitHub

git init

$ git init

Initialized empty Git repository in /home/lucas/workspace/demo-git/.git/

Page 27: Introducción a git y GitHub

git status

$ git status# On branch master## Initial commit## Untracked files:# (use "git add <file>..." to include in what will be committed)## README.mdnothing added to commit but untracked files present (use "git add" to track)

Page 28: Introducción a git y GitHub

git add

$ git add README.md$ git status# On branch master## Initial commit## Changes to be committed:# (use "git rm --cached <file>..." to unstage)## new file: README.md#

Page 29: Introducción a git y GitHub

git status$ git status# On branch master# Initial commit# Changes to be committed:# (use "git rm --cached <file>..." to unstage)# new file: README.md## Changes not staged for commit:# (use "git add <file>..." to update what will be committed)# (use "git checkout -- <file>..." to discard changes in working directory)# modified: README.md## Untracked files:# (use "git add <file>..." to include in what will be committed)# index.html

Page 30: Introducción a git y GitHub

git add

$ git add .$ git status# On branch master## Initial commit## Changes to be committed:# (use "git rm --cached <file>..." to unstage)## new file: README.md# new file: index.html#

Page 31: Introducción a git y GitHub

git commit

$ git commit -m "Commit inicial"[master (root-commit) 0b8f623] Commit inicial 2 files changed, 4 insertions(+) create mode 100644 README.md create mode 100644 index.html

$ git status# On branch masternothing to commit (working directory clean)

Page 32: Introducción a git y GitHub

git status$ vim README.md$ git status# On branch master# Changes not staged for commit:# (use "git add <file>..." to update what will be committed)# (use "git checkout -- <file>..." to discard changes in working directory)## modified: README.md#

Page 33: Introducción a git y GitHub

git commit

$ git commit -am "Cambios en el readme"[master 088d366] Cambios en el readme 1 file changed, 1 insertion(+), 1 deletion(-)

Page 34: Introducción a git y GitHub

git log

$ git logcommit 088d366628eeb349ee612123ca6267ca3f98ba2cAuthor: Lucas Videla <[email protected]>Date: Wed Aug 15 14:21:40 2012 -0300

Cambios en el readme

commit 0b8f623aa377049c1b9a41da5b8ea6de0722cb74Author: Lucas Videla <[email protected]>Date: Wed Aug 15 14:16:18 2012 -0300

Commit inicial

Page 35: Introducción a git y GitHub

git log

$ git logcommit 088d366628eeb349ee612123ca6267ca3f98ba2cAuthor: Lucas Videla <[email protected]>Date: Wed Aug 15 14:21:40 2012 -0300

Cambios en el readme

commit 0b8f623aa377049c1b9a41da5b8ea6de0722cb74Author: Lucas Videla <[email protected]>Date: Wed Aug 15 14:16:18 2012 -0300

Commit inicial

Page 36: Introducción a git y GitHub

git log

$ git logcommit 088d366628eeb349ee612123ca6267ca3f98ba2cAuthor: Lucas Videla <[email protected]>Date: Wed Aug 15 14:21:40 2012 -0300

Cambios en el readme

commit 0b8f623aa377049c1b9a41da5b8ea6de0722cb74Author: Lucas Videla <[email protected]>Date: Wed Aug 15 14:16:18 2012 -0300

Commit inicial

Page 37: Introducción a git y GitHub

git log

$ git logcommit 088d366628eeb349ee612123ca6267ca3f98ba2cAuthor: Lucas Videla <[email protected]>Date: Wed Aug 15 14:21:40 2012 -0300

Cambios en el readme

commit 0b8f623aa377049c1b9a41da5b8ea6de0722cb74Author: Lucas Videla <[email protected]>Date: Wed Aug 15 14:16:18 2012 -0300

Commit inicial

Page 38: Introducción a git y GitHub

git log

$ git logcommit 088d366628eeb349ee612123ca6267ca3f98ba2cAuthor: Lucas Videla <[email protected]>Date: Wed Aug 15 14:21:40 2012 -0300

Cambios en el readme

commit 0b8f623aa377049c1b9a41da5b8ea6de0722cb74Author: Lucas Videla <[email protected]>Date: Wed Aug 15 14:16:18 2012 -0300

Commit inicial

Page 39: Introducción a git y GitHub

git lol*

$ git lol* 088d366 (HEAD, master) Cambios en el readme* 0b8f623 Commit inicial

088d366

0b8f623

HEAD master

Page 40: Introducción a git y GitHub

git branch

$ git branch* master

$ git checkout -b fondoAzulSwitched to a new branch 'fondoAzul'

$ git branch* fondoAzul master

088d366

0b8f623

HEAD master fondoAzul

Page 41: Introducción a git y GitHub

git add

$ vim index.html $ git commit -am "Se cambia el fondo a azul"[fondoAzul d20ddf9] Se cambia el fondo a azul 1 file changed, 1 insertion(+), 1 deletion(-)

088d366

0b8f623

HEAD

master

fondoAzuld20ddf9

Page 42: Introducción a git y GitHub

git checkout$ git checkout masterSwitched to branch 'master'

$ vim index.html $ git commit -am "Se cambia la letra a título"[master 45ba368] Se cambia la letra a título 1 file changed, 1 insertion(+), 1 deletion(-)

088d366

0b8f623

HEADmasterfondoAzuld20ddf9 45ba368

Page 43: Introducción a git y GitHub

git merge$ git merge fondoAzulAuto-merging index.htmlMerge made by the 'recursive' strategy. index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)

088d366

0b8f623

HEADmaster

fondoAzuld20ddf9

e9de90a

45ba368

Page 44: Introducción a git y GitHub

git tag$ git tag -a v0.0.1 -m "Primera versión del sitio"

$ git tagV0.0.1

088d366

0b8f623

HEADmaster

fondoAzuld20ddf9

e9de90a tag: v0.0.1

45ba368

Page 45: Introducción a git y GitHub

git branch ­d$ git branch -d fondoAzulDeleted branch fondoAzul (was ce1c815).

088d366

0b8f623

HEADmaster

d20ddf9

e9de90a tag: v0.0.1

45ba368

Page 46: Introducción a git y GitHub

git checkout$ git checkout 088d366 index.html

088d366

0b8f623

HEADmaster

d20ddf9

e9de90a tag: v0.0.1

?

45ba368

Page 47: Introducción a git y GitHub

git diff$ git diff --cacheddiff --git a/index.html b/index.htmlindex 1007883..ae750ea 100644--- a/index.html+++ b/index.html@@ -1,7 +1,7 @@ <html> <head> </head>-<body style="background-color: blue;">+<body> <h1>Bienvenido!</h1>

Page 48: Introducción a git y GitHub

git commit$ git commit -am "Se restaura index"[master f2736c8] Se restaura index 1 file changed, 1 insertion(+), 1 deletion(-)

088d366

0b8f623

HEADmaster

d20ddf9

e9de90a tag: v0.0.1

f2736c8

45ba368

Page 49: Introducción a git y GitHub

Breve repaso

git configgit initgit addgit commitgit loggit branchgit checkoutgit diff

Page 50: Introducción a git y GitHub

Breve repaso

git configgit initgit addgit commitgit loggit branchgit checkoutgit diff

Page 51: Introducción a git y GitHub

workflow git básico

(a.k.a. “cómo trabajar con git”)

Page 52: Introducción a git y GitHub

directoriode trabajo

index

repositorio

Page 53: Introducción a git y GitHub

directoriode trabajo

index

repositorio

la copia de trabajo del proyecto

el estado intermedio, stage

base de datos con la historia del proyecto

Page 54: Introducción a git y GitHub

1. editar archivos

2. pasar a stage

3. revisar cambios

4. hacer commit

Page 55: Introducción a git y GitHub

directoriode trabajo

index

repositorio

git add

git commit

Page 56: Introducción a git y GitHub

git remoto

Page 57: Introducción a git y GitHub

demo 2 ㋡

Page 58: Introducción a git y GitHub

http://github.com

Page 59: Introducción a git y GitHub
Page 60: Introducción a git y GitHub
Page 61: Introducción a git y GitHub

git remote$ git remote add origin [email protected]:delucas/demo-git.git

$ git remoteorigin

Page 62: Introducción a git y GitHub

git push$ git push origin masterCounting objects: 17, done.Delta compression using up to 4 threads.Compressing objects: 100% (15/15), done.Writing objects: 100% (17/17), 1.66 KiB, done.Total 17 (delta 2), reused 0 (delta 0)To [email protected]:delucas/demo-git.git * [new branch] master -> master

Page 63: Introducción a git y GitHub

¡Momento!

088d366

0b8f623

HEAD

origin/master

d20ddf9

e9de90a tag: v0.0.1

f2736c8

45ba368

master

Page 64: Introducción a git y GitHub

git clone$ git clone [email protected]:delucas/demo-git.gitCloning into demo-git...remote: Counting objects: 17, done.remote: Compressing objects: 100% (13/13), done.remote: Total 17 (delta 2), reused 17 (delta 2)Receiving objects: 100% (17/17), done.Resolving deltas: 100% (2/2), done.

Page 65: Introducción a git y GitHub

git pull$ git pull origin masterremote: Counting objects: 5, done.remote: Compressing objects: 100% (3/3), done.remote: Total 3 (delta 0), reused 3 (delta 0)Unpacking objects: 100% (3/3), done.From github.com:delucas/demo-git * branch master -> FETCH_HEADUpdating f2736c8..5c565c5Fast-forward index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)

Page 66: Introducción a git y GitHub

¡Momento!

088d366

0b8f623

HEAD

origin/master

d20ddf9

e9de90a tag: v0.0.1

f2736c8

45ba368

master5c565c5

Page 67: Introducción a git y GitHub

git commit$ git commit -am "Se establece fondo azul"[master aca1dbf] Se establece fondo azul 1 file changed, 1 insertion(+), 1 deletion(-)

Page 68: Introducción a git y GitHub

¡Momento!

088d366

0b8f623

HEAD

origin/master

d20ddf9

e9de90a tag: v0.0.1

f2736c8

45ba368

master

5c565c5

aca1dbf

Page 69: Introducción a git y GitHub

git push$ git push origin masterTo [email protected]:delucas/demo-git.git ! [rejected] master -> master (non-fast-forward)error: failed to push some refs to '[email protected]:delucas/demo-git.git'To prevent you from losing history, non-fast-forward updates were rejectedMerge the remote changes (e.g. 'git pull') before pushing again. See the'Note about fast-forwards' section of 'git push --help' for details.

Page 70: Introducción a git y GitHub

git pull$ git pull origin masterremote: Counting objects: 8, done.remote: Compressing objects: 100% (6/6), done.remote: Total 6 (delta 0), reused 6 (delta 0)Unpacking objects: 100% (6/6), done.From github.com:delucas/demo-git * branch master -> FETCH_HEADAuto-merging index.htmlCONFLICT (content): Merge conflict in index.htmlAutomatic merge failed; fix conflicts and then commit the result.

Page 71: Introducción a git y GitHub

¡Momento!

088d366

0b8f623

HEADorigin/master

d20ddf9

e9de90a tag: v0.0.1

27ac778

45ba368

master

5c565c5

aca1dbf

f2736c8

Page 72: Introducción a git y GitHub

git diff$ git diffdiff --cc index.htmlindex fba4d43,f5f9763..0000000--- a/index.html+++ b/index.html@@@ -1,7 -1,7 +1,11 @@@ <html> <head> </head>++<<<<<<< HEAD +<body style="background-color:blue;">++=======+ <body style="background-color:red;">++>>>>>>> 27ac778abf019e73d9bb3eb99b10cce0877b9108 <h1>Welcome!</h1>

Page 73: Introducción a git y GitHub

git diff$ git status# On branch master# Unmerged paths:# (use "git add/rm <file>..." as appropriate to mark resolution)## both modified: index.htmlno changes added to commit (use "git add" and/or "git commit -a")$ git diffdiff --cc index.htmlindex fba4d43,f5f9763..0000000--- a/index.html+++ b/index.html$ git commit -am "Se resuelve conflicto de merge"[master e3be094] Se resuelve conflicto de merge

Page 74: Introducción a git y GitHub

¡Momento!

088d366

0b8f623

HEAD

origin/master

d20ddf9

e9de90a tag: v0.0.1

27ac778

45ba368

master

5c565c5

aca1dbf

f2736c8

e3be094

Page 75: Introducción a git y GitHub

git push$ git push origin masterCounting objects: 8, done.Delta compression using up to 4 threads.Compressing objects: 100% (4/4), done.Writing objects: 100% (4/4), 503 bytes, done.Total 4 (delta 1), reused 0 (delta 0)To [email protected]:delucas/demo-git.git 27ac778..e3be094 master -> master

Page 76: Introducción a git y GitHub

¡Momento!

088d366

0b8f623

HEAD

origin/master

d20ddf9

e9de90a tag: v0.0.1

27ac778

45ba368

master

5c565c5

aca1dbf

f2736c8

e3be094

Page 77: Introducción a git y GitHub

entendiendo git

Page 78: Introducción a git y GitHub

snapshots, no parches

gracias, Scott! (@chacon)

Page 79: Introducción a git y GitHub
Page 80: Introducción a git y GitHub
Page 81: Introducción a git y GitHub
Page 82: Introducción a git y GitHub
Page 83: Introducción a git y GitHub
Page 84: Introducción a git y GitHub
Page 85: Introducción a git y GitHub
Page 86: Introducción a git y GitHub
Page 87: Introducción a git y GitHub
Page 88: Introducción a git y GitHub
Page 89: Introducción a git y GitHub
Page 90: Introducción a git y GitHub
Page 91: Introducción a git y GitHub
Page 92: Introducción a git y GitHub
Page 93: Introducción a git y GitHub
Page 94: Introducción a git y GitHub

el modelo de objetos

Page 95: Introducción a git y GitHub

el modelo de objetos

Page 96: Introducción a git y GitHub

el objeto commit

Page 97: Introducción a git y GitHub

el objeto commit

Page 98: Introducción a git y GitHub

el objeto commit

Page 99: Introducción a git y GitHub
Page 100: Introducción a git y GitHub
Page 101: Introducción a git y GitHub
Page 102: Introducción a git y GitHub
Page 103: Introducción a git y GitHub
Page 104: Introducción a git y GitHub
Page 105: Introducción a git y GitHub
Page 106: Introducción a git y GitHub

los branches

Page 107: Introducción a git y GitHub
Page 108: Introducción a git y GitHub

(es un puntero a un commit)

Page 109: Introducción a git y GitHub
Page 110: Introducción a git y GitHub

HEAD

Page 111: Introducción a git y GitHub
Page 112: Introducción a git y GitHub

git branch experiment

Page 113: Introducción a git y GitHub
Page 114: Introducción a git y GitHub

git checkout experiment

Page 115: Introducción a git y GitHub

git commit

Page 116: Introducción a git y GitHub

git commit

Page 117: Introducción a git y GitHub

git checkout default

Page 118: Introducción a git y GitHub

git commit

Page 119: Introducción a git y GitHub

git checkout experimentgit commit

Page 120: Introducción a git y GitHub

merge

Page 121: Introducción a git y GitHub

git checkout default

Page 122: Introducción a git y GitHub

git merge experiment

Page 123: Introducción a git y GitHub
Page 124: Introducción a git y GitHub

(pausa)

Page 125: Introducción a git y GitHub

¿preguntas?

Page 126: Introducción a git y GitHub

recursos git

Page 127: Introducción a git y GitHub

git­scm.com

Page 128: Introducción a git y GitHub

help.github.com

Page 129: Introducción a git y GitHub

gitimmersion.com

Page 130: Introducción a git y GitHub

gitcasts.com

Page 131: Introducción a git y GitHub

codeschool.com/courses/try­git

Page 132: Introducción a git y GitHub

nvie.com/posts/a­successful­git­branching­model/

Page 133: Introducción a git y GitHub

¡muchas gracias!

@luke_ar@matitanio#charlagit