gitflow - una metología para manejo de branches
DESCRIPTION
Introducción a la metodolgía Gitflow para manejo efectivo de codigó fuente utilizando Git.TRANSCRIPT
GitFlowJavier Alvarez
@JManGT
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/.
GITVersionamiento de Código
Lo BásicoEnvironments, Branches, Tags, Merge
Environments
Desarrollo
Vagrant + Puppet
Pruebas Producción
Branches$ git branch> * master
Branches$ git branch mi-branch > * master mi-branch
BranchesMaster
abc001
abc002
….
abc008
commits
branch
BranchesMaster
abc001
abc002
….
abc008
Mi-branch
xyz001
xyz002
…
$ git checkout mi-branch
TagsMaster
abc001
abc002
….
abc123
Mi-branch
xyz001
xyz002
…
V0.2.0V0.1.0 xyz025
$ git tag –a v0.2.0
TagsMaster
abc001
abc002
….
abc123
Mi-branch
xyz001
xyz002
…
V0.2.0V0.1.0 xyz025
TagsMaster
abc001
abc002
….
abc123
Mi-branch
xyz001
xyz002
…
V0.2.0V0.1.0 xyz025
opq001
Experimento
$ git branch experimento
MergeMaster
abc001
abc002
….
abc123Mi-branch
xyz001
xyz002
V0.1.0xyz025
xyz025 V0.2.0
$ git merge experimiento
MergeMaster
abc001
abc002
….
abc123Mi-branch
xyz001
xyz002
V0.1.0xyz025
xyz025 V0.2.0
$ git branch -D mi-branch
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
WorkflowProblemas Comunes
Master a Master
MasterMaster
Mi Máquina El Server
$ git push server master
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
Master / EdgeMasterMaster
Mi Máquina El Server
Dos branches en la máquina de desarrollo
Edge
V0.1.0 abc001
abc123
Master / EdgeMasterMaster
Mi Máquina El Server
Podemos corregir el bug directamente a master
Edge
V0.1.0 abc001
abc123
Master / EdgeMasterMaster
Mi Máquina El Server
Agregamos el bugfix a Edge
Edge
V0.1.0 abc001
abc123
xyz001 xyz001
xyz001
WorkflowTrabajo en Equipo
En EquipoMaster
Cada desarrollador trabaja a partir de Edge
Edge
abc123
abc001V0.1.0
Edge
xyz033
Edge
opq654
Pedro Juan
ReleaseMaster
Todos hacen push a edge
Edge
abc001V0.1.0
Edge Edge
Pedro Juan
V0.2.0
Release
Lo que se prueba no es lo que se libera
Master
ProducciónPruebas
Edge
Bug - MarioFeature - JuanMario - Edge
GitflowMetodología de Branching
Branches Principales
Master
2 branch permanentes
Edge
Commit Inicial
Version 1.0
Version 2.0Nuevos Features
Branches Desarrollo
Principales• Master• Edge
Desarrollo• Feature• Release• Hotfix
Feature Branch
Independizar el desarrollo de features
Feature Branch
Master
Branch temporal hasta completar el feature
Edge
Commit Inicial
Version 1.0
Version 2.0
Feature
Feature Completo
Feature Branch
Generamos un nuevo feature branch desde edge
EdgeFeature
Feature Completo
$ git checkout feature edge
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
Feature Branch
Multiples feature branches se actualizan desde Edge
Edgefeature/Bfeature/A
Release BranchCongelar y Estabilizar
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”
Release Branch
Estabilizamos el código del release
Edge Release
Feature/A
Master
V0.1.0
Código estable
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
Finalizar Release
Dos pasos para finalizar el Release Branch
Edge Release/0.2.0Master
V0.1.0
v0.2.0
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
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
Finalizar Release
Eliminamos el release branch
Edge Release/0.2.0Master
V0.1.0
$ git branch –d release/0.2.0
V0.2.0
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
Hotfix BranchCorreción de Errores FATALES
Hotfix Branch
Hotfix branch nace desde Master
Hotfix MasterEdge
v0.2.0
v0.2.1
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”
Hotfix Branch
Corregimos el bug
Hotfix MasterEdge
v0.2.0
$ git commit –am “Fix bug #123”
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
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
Finalizar Hotfix
Eliminamos el Hotfix Branch
Hotfix MasterEdge
v0.2.0
$ git branch –d hotfix/0.2.1
v0.2.1
Gitflow Git plugin
https://github.com/nvie/gitflow
Gitflow Git plugin
Ubuntu
# apt-get install git-flow
Fedora
# yum install gitflow
Mac
$ brew install git-flow
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) ✗
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) ✗
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)
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)
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)
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)
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)
A successful Git branching
modelhttp://nvie.com/posts/a-successful-git-branching-model/
Gracias
por su sinton
ía@JmanGtJavier Alvarez