60
GitFlow Javier Alvarez @JManGT

Gitflow - Una metología para manejo de Branches

Embed Size (px)

DESCRIPTION

Introducción a la metodolgía Gitflow para manejo efectivo de codigó fuente utilizando Git.

Citation preview

Page 1: Gitflow - Una metología para manejo de Branches

GitFlowJavier Alvarez

@JManGT

Page 2: Gitflow - Una metología para manejo de Branches

Esta obra está licenciada bajo la Licencia Creative Commons Atribución-CompartirIgual 4.0 Internacional. Para ver una copia de esta licencia, visita http://creativecommons.org/licenses/by-sa/4.0/.

Page 3: Gitflow - Una metología para manejo de Branches

GITVersionamiento de Código

Page 4: Gitflow - Una metología para manejo de Branches

Lo BásicoEnvironments, Branches, Tags, Merge

Page 5: Gitflow - Una metología para manejo de Branches

Environments

Desarrollo

Vagrant + Puppet

Pruebas Producción

Page 6: Gitflow - Una metología para manejo de Branches

Branches$ git branch> * master

Page 7: Gitflow - Una metología para manejo de Branches

Branches$ git branch mi-branch > * master mi-branch

Page 8: Gitflow - Una metología para manejo de Branches

BranchesMaster

abc001

abc002

….

abc008

commits

branch

Page 9: Gitflow - Una metología para manejo de Branches

BranchesMaster

abc001

abc002

….

abc008

Mi-branch

xyz001

xyz002

$ git checkout mi-branch

Page 10: Gitflow - Una metología para manejo de Branches

TagsMaster

abc001

abc002

….

abc123

Mi-branch

xyz001

xyz002

V0.2.0V0.1.0 xyz025

$ git tag –a v0.2.0

Page 11: Gitflow - Una metología para manejo de Branches

TagsMaster

abc001

abc002

….

abc123

Mi-branch

xyz001

xyz002

V0.2.0V0.1.0 xyz025

Page 12: Gitflow - Una metología para manejo de Branches

TagsMaster

abc001

abc002

….

abc123

Mi-branch

xyz001

xyz002

V0.2.0V0.1.0 xyz025

opq001

Experimento

$ git branch experimento

Page 13: Gitflow - Una metología para manejo de Branches

MergeMaster

abc001

abc002

….

abc123Mi-branch

xyz001

xyz002

V0.1.0xyz025

xyz025 V0.2.0

$ git merge experimiento

Page 14: Gitflow - Una metología para manejo de Branches

MergeMaster

abc001

abc002

….

abc123Mi-branch

xyz001

xyz002

V0.1.0xyz025

xyz025 V0.2.0

$ git branch -D mi-branch

Page 15: Gitflow - Una metología para manejo de Branches

CheckoutMaster

abc001

abc002

….

abc123 V0.1.0

xyz025 V0.2.0$ git clone repo$ git tags –l> v0.2.0 v0.1.0$ git checkout tags/v0.2.0$ git checkout tags/v0.1.0

Page 16: Gitflow - Una metología para manejo de Branches

WorkflowProblemas Comunes

Page 17: Gitflow - Una metología para manejo de Branches

Master a Master

MasterMaster

Mi Máquina El Server

$ git push server master

Page 18: Gitflow - Una metología para manejo de Branches

Master a Master

MasterMaster

El Server

No es posible corregir el bug hasta completar el feature

V0.1.0 abc001

abc002

Nuevo Feature abc001

abc003

abc123 ¡BUG!Feature Incompleto

Page 19: Gitflow - Una metología para manejo de Branches

Master / EdgeMasterMaster

Mi Máquina El Server

Dos branches en la máquina de desarrollo

Edge

V0.1.0 abc001

abc123

Page 20: Gitflow - Una metología para manejo de Branches

Master / EdgeMasterMaster

Mi Máquina El Server

Podemos corregir el bug directamente a master

Edge

V0.1.0 abc001

abc123

Page 21: Gitflow - Una metología para manejo de Branches

Master / EdgeMasterMaster

Mi Máquina El Server

Agregamos el bugfix a Edge

Edge

V0.1.0 abc001

abc123

xyz001 xyz001

xyz001

Page 22: Gitflow - Una metología para manejo de Branches

WorkflowTrabajo en Equipo

Page 23: Gitflow - Una metología para manejo de Branches

En EquipoMaster

Cada desarrollador trabaja a partir de Edge

Edge

abc123

abc001V0.1.0

Edge

xyz033

Edge

opq654

Pedro Juan

Page 24: Gitflow - Una metología para manejo de Branches

ReleaseMaster

Todos hacen push a edge

Edge

abc001V0.1.0

Edge Edge

Pedro Juan

V0.2.0

Page 25: Gitflow - Una metología para manejo de Branches

Release

Lo que se prueba no es lo que se libera

Master

ProducciónPruebas

Edge

Bug - MarioFeature - JuanMario - Edge

Page 26: Gitflow - Una metología para manejo de Branches

GitflowMetodología de Branching

Page 27: Gitflow - Una metología para manejo de Branches

Branches Principales

Master

2 branch permanentes

Edge

Commit Inicial

Version 1.0

Version 2.0Nuevos Features

Page 28: Gitflow - Una metología para manejo de Branches

Branches Desarrollo

Principales• Master• Edge

Desarrollo• Feature• Release• Hotfix

Page 29: Gitflow - Una metología para manejo de Branches

Feature Branch

Independizar el desarrollo de features

Page 30: Gitflow - Una metología para manejo de Branches

Feature Branch

Master

Branch temporal hasta completar el feature

Edge

Commit Inicial

Version 1.0

Version 2.0

Feature

Feature Completo

Page 31: Gitflow - Una metología para manejo de Branches

Feature Branch

Generamos un nuevo feature branch desde edge

EdgeFeature

Feature Completo

$ git checkout feature edge

Page 32: Gitflow - Una metología para manejo de Branches

Feature Branch

Completamos el feature haciendo merge a edge y borrando el feature branch

EdgeFeature

Feature Completo$ git checkout edge$ git merge –no-ff feature$ git branch –d feature$ git push origin develop

Page 33: Gitflow - Una metología para manejo de Branches

Feature Branch

Multiples feature branches se actualizan desde Edge

Edgefeature/Bfeature/A

Page 34: Gitflow - Una metología para manejo de Branches

Release BranchCongelar y Estabilizar

Page 35: Gitflow - Una metología para manejo de Branches

Release Branch

Congelamos el código del release

Edge Release/0.2.0

Feature/A

Master

Bump a 0.2.0

V0.1.0

$ git checkout –b release/0.2.0 edge< bump de la version de mi codigo >$ git commit –am “Bump 0.2.0”

Page 36: Gitflow - Una metología para manejo de Branches

Release Branch

Estabilizamos el código del release

Edge Release

Feature/A

Master

V0.1.0

Código estable

Page 37: Gitflow - Una metología para manejo de Branches

Release Branch

Edge puede segir avanzando independientemente

Edge Release

Feature/A

Master

v0.2.0

V0.1.0

Feature/B

Feature/C Código estable

Page 38: Gitflow - Una metología para manejo de Branches

Finalizar Release

Dos pasos para finalizar el Release Branch

Edge Release/0.2.0Master

V0.1.0

v0.2.0

Page 39: Gitflow - Una metología para manejo de Branches

Finalizar Release

Merge de feature a master. Generar release tag.

Edge Release/0.2.0Master

V0.1.0

$ git checkout master$ git merge –no-ff release/0.2.0$ git tag –a v0.2.0

V0.2.0

Page 40: Gitflow - Una metología para manejo de Branches

Finalizar Release

Merge de feature a master. Generar release tag.

Edge Release/0.2.0Master

V0.1.0

$ git checkout develop$ git merge –no-ff release/0.2.0$ git tag –a v0.2.0

V0.2.0

Page 41: Gitflow - Una metología para manejo de Branches

Finalizar Release

Eliminamos el release branch

Edge Release/0.2.0Master

V0.1.0

$ git branch –d release/0.2.0

V0.2.0

Page 42: Gitflow - Una metología para manejo de Branches

Finalizar Release

Master está estable y Edge tiene nuevos features.

Release/0.2.0Master

V0.1.0

V0.2.0

Edge

Feature/A

Feature/A

Feature/A

Feature/B

Feature/C

A, B y C

Page 43: Gitflow - Una metología para manejo de Branches

Hotfix BranchCorreción de Errores FATALES

Page 44: Gitflow - Una metología para manejo de Branches

Hotfix Branch

Hotfix branch nace desde Master

Hotfix MasterEdge

v0.2.0

v0.2.1

Page 45: Gitflow - Una metología para manejo de Branches

Hotfix Branch

Generamos un hotfix branch y hacemos bump de la version

Hotfix MasterEdge

v0.2.0

$ git branch –d hotfix/0.2.1 master<Bump de version a 0.2.1>$ git commit –am “Bump a 0.2.1”

Page 46: Gitflow - Una metología para manejo de Branches

Hotfix Branch

Corregimos el bug

Hotfix MasterEdge

v0.2.0

$ git commit –am “Fix bug #123”

Page 47: Gitflow - Una metología para manejo de Branches

Finalizar Hotfix

Finalizamos Hotfix branch haciendo merge a master.

Hotfix MasterEdge

v0.2.0

$ git checkout master$ git merge –-no-ff hotfix/0.2.1$ git tag –a 0.2.1

v0.2.1

Page 48: Gitflow - Una metología para manejo de Branches

Finalizar Hotfix

Incluimos el parche tambien en edge.

Hotfix MasterEdge

v0.2.0

$ git checkout edge$ git merge –-no-ff hotfix/0.2.1

v0.2.1

Page 49: Gitflow - Una metología para manejo de Branches

Finalizar Hotfix

Eliminamos el Hotfix Branch

Hotfix MasterEdge

v0.2.0

$ git branch –d hotfix/0.2.1

v0.2.1

Page 50: Gitflow - Una metología para manejo de Branches

Gitflow Git plugin

https://github.com/nvie/gitflow

Page 51: Gitflow - Una metología para manejo de Branches

Gitflow Git plugin

Ubuntu

# apt-get install git-flow

Fedora

# yum install gitflow

Mac

$ brew install git-flow

Page 52: Gitflow - Una metología para manejo de Branches

Inicializar Repositorio

➜ mi-app git:(master) ✗ git flow initNo branches exist yet. Base branches must be created now.Branch name for production releases: [master]Branch name for "next release" development: [develop] edge

How to name your supporting branch prefixes?Feature branches? [feature/]Release branches? [release/]Hotfix branches? [hotfix/]Support branches? [support/]Version tag prefix? []➜ mi-app git:(edge) ✗

Page 53: Gitflow - Una metología para manejo de Branches

Feature Branch➜ mi-app git:(edge) ✗ git flow feature start homepageSwitched to a new branch 'feature/homepage'

Summary of actions:- A new branch 'feature/homepage' was created, based on 'edge'- You are now on branch 'feature/homepage'

Now, start committing on your feature. When done, use:

git flow feature finish homepage

➜ mi-app git:(feature/homepage) ✗

Page 54: Gitflow - Una metología para manejo de Branches

Finalizar Feature Branch

➜ mi-app git:(feature/homepage) git flow feature finish homepageSwitched to branch 'edge'Updating 4d2c7d8..0812b3bFast-forward hello.txt | 0 homepage.html | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 hello.txt create mode 100644 homepage.htmlDeleted branch feature/homepage (was 0812b3b).

Summary of actions:- The feature branch 'feature/homepage' was merged into 'edge'- Feature branch 'feature/homepage' has been removed- You are now on branch 'edge'

➜ mi-app git:(edge)

Page 55: Gitflow - Una metología para manejo de Branches

Release Branch➜ mi-app git:(edge) git flow release start v0.1.0Switched to a new branch 'release/v0.1.0'

Summary of actions:- A new branch 'release/v0.1.0' was created, based on 'edge'- You are now on branch 'release/v0.1.0'

Follow-up actions:- Bump the version number now!- Start committing last-minute fixes in preparing your release- When done, run:

git flow release finish 'v0.1.0’

➜ mi-app git:(release/v0.1.2)

Page 56: Gitflow - Una metología para manejo de Branches

Release Branch➜ mi-app git:(release/v0.1.0) git flow release finish v0.1.0Switched to branch 'master'Merge made by the 'recursive' strategy. hello.txt | 0 homepage.html | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 hello.txt create mode 100644 homepage.htmlDeleted branch release/v0.1.0 (was 0812b3b).

Summary of actions:- Latest objects have been fetched from 'origin'- Release branch has been merged into 'master'- The release was tagged 'v0.1.0'- Release branch has been back-merged into 'edge'- Release branch 'release/v0.1.0' has been deleted

➜ mi-app git:(master)

Page 57: Gitflow - Una metología para manejo de Branches

Hotfix Branch➜ mi-app git:(master) git flow hotfix start v0.1.1Switched to a new branch 'hotfix/v0.1.1'

Summary of actions:- A new branch 'hotfix/v0.1.1' was created, based on 'master'- You are now on branch 'hotfix/v0.1.1'

Follow-up actions:- Bump the version number now!- Start committing your hot fixes- When done, run:

git flow hotfix finish 'v0.1.1'

➜ mi-app git:(hotfix/v0.1.1)

Page 58: Gitflow - Una metología para manejo de Branches

Hotfix Branch➜ mi-app git:(hotfix/v0.1.1) ✗ git commit -am "Fix bug #123"[hotfix/v0.1.1 f7f9caa] Fix bug #123 1 file changed, 1 insertion(+)➜ mi-app git:(hotfix/v0.1.1) git flow hotfix finish v0.1.1Switched to branch 'master'Merge made by the 'recursive' strategy. homepage.html | 1 + 1 file changed, 1 insertion(+)Switched to branch 'edge'Merge made by the 'recursive' strategy. homepage.html | 1 + 1 file changed, 1 insertion(+)Deleted branch hotfix/v0.1.1 (was f7f9caa).

Summary of actions:- Latest objects have been fetched from 'origin'- Hotfix branch has been merged into 'master'- The hotfix was tagged 'v0.1.1'- Hotfix branch has been back-merged into 'edge'- Hotfix branch 'hotfix/v0.1.1' has been deleted

➜ mi-app git:(edge)

Page 59: Gitflow - Una metología para manejo de Branches

A successful Git branching

modelhttp://nvie.com/posts/a-successful-git-branching-model/

Page 60: Gitflow - Una metología para manejo de Branches

Gracias

por su sinton

ía@JmanGtJavier Alvarez