Git-FlowUn modèle de versionnement efficace avec Git
Philippe [email protected] juin 2017
CNRS/IPAG/OSUG
Plan
1. Présentation
2. Modèle de branches
3. Cas pratique
4. Bilan
2
Présentation
Git-Flow, c’est quoi ?
Une extension de Git
• disponible sur GNU/Linux, BSD, MacOS, Windows• rajoute un ensemble de sous-commandes à Git• automatise une série de commandes Git pour une action précise
Un ensemble de bonnes pratiques
• standardise l’organisation d’un dépôt Git• clarifie le nommage des branches• impose un workflow pour le développement d’un projet• convient au développement agile (type SCRUM)
3
Comment l’installer et s’en servir ?
Avec Debian, c’est très simple !sudo apt−get i n s t a l l g i t−f low
Pour les autres... RTFM :)github.com/petervanderdoes/gitflow-avh/wiki/Installation
Quelques liens utiles
• danielkummer.github.io/git-flow-cheatsheet/
• github.com/petervanderdoes/gitflow-avh/wiki/
• nvie.com/posts/a-successful-git-branching-model/
• raphaelhertzog.fr/livre/memento-git/
Au fait, la bonne version, c’est Gitflow-AVH...
4
Modèle de branches
Organisation des branches
5
Rôle des branches principales
master
• contient la dernière version stable du produit livrable et opérationnel• ne reçoit aucun commit direct
develop
• devient la branche principale, véritable colonne vertébrale du dépôt• branche d’intégration des développements• ne reçoit, si possible, aucun commit direct
feature/mabranche
• branche de développement isolé d’une fonctionnalité• créée à partir de develop• sera fusionnée dans develop puis détruite
6
Rôle des branches secondaires
release/mabranche
• branche de préparation à la livraison d’une nouvelle version• permet de stabiliser une livraison sans bloquer le développement• créée à partir de develop• sera fusionnée dans master et dans develop puis détruite• génère la création d’un tag identifiant la version
hotfix/mabranche
• branche de réalisation d’un correctif• permet de corriger un bug en prod sans bloquer le développement• créée à partir de master• sera fusionnée dans master et dans develop puis détruite• génère la création d’un tag identifiant la version
7
Commandes
8
Cas pratique
Initialisation d’un dépôt Git
Création d’un dépôt local~/$ mkdir demo~/$ cd ~/demo~/demo$ g i t i n i t~/demo$ touch README.md~/demo$ g i t add README.md~/demo$ g i t commit −m ” I n i t i a l commit”
~/demo$ g i t remote add o r i g i n git@maforge . f r /demo . g i t~/demo$ g i t push −u o r i g i n master
En clonant un dépôt vide existant~/$ g i t c lone git@maforge . f r /demo . g i t~/$ cd demo~/demo$ touch README.md~/demo$ g i t add README.md~/demo$ g i t commit −m ”add README”~/demo$ g i t push −u o r i g i n master
9
Initialisation de Git-Flow pour ce dépôt
Initialiser git-flow~/demo$ g i t f low i n i t
Répondre aux questionsNo branches e x i s t yet . Base branches must be created now .Branch name fo r product ion r e l e a s e s : [ master ]Branch name fo r ”next r e l e a s e ” development : [ deve lop ]
How to name your support ing branch p r e f i x e s ?Feature branches ? [ f e a tu r e / ]Re lease branches ? [ r e l e a s e /]Hot f i x branches ? [ h o t f i x / ]Support branches ? [ support / ]Vers ion tag p r e f i x ? [ ] tag/Hooks and f i l t e r s d i r e c t o r y ? [~/demo/. g i t /hooks ]
10
Création d’une fonctionnalité 1
Se placer dans develop (automatique après init)~/demo$ g i t checkout developBasculement sur l a branche ’ develop ’
Créer la branche de fonctionnalité 1~/demo$ g i t f low f ea tu r e s t a r t mafonction1Basculement sur l a nouve l l e branche ’ f e a tu r e /mafonction1 ’
Summary of ac t i on s :− A new branch ’ f e a tu r e /mafonction1 ’ was created , based on ’ develop ’− You are now on branch ’ f e a tu r e /mafonction1 ’
Now, s t a r t committing on your f e a tu r e . When done , use :
g i t f low f ea tu r e f i n i s h mafonction1
11
Développement d’une fonctionnalité 1
Pour faire simple, on ajoute un fichier...~/demo$ touch fonct ion1 . t x t~/demo$ g i t add fonct ion1 . t x t~/demo$ g i t commit −m ”Fonction 1”[ f e a tu r e /mafonction1 6a44a23 ] Fonction 11 f i l e changed , 0 i n s e r t i o n s (+) , 0 d e l e t i o n s (−)c r ea te mode 100644 fonct ion1 . t x t
12
Création d’une fonctionnalité 2
Se placer dans develop~/demo$ g i t checkout developBasculement sur l a branche ’ develop ’
Créer la branche de fonctionnalité 2~/demo$ g i t f low f ea tu r e s t a r t mafonction2Basculement sur l a nouve l l e branche ’ f e a tu r e /mafonction2 ’
Summary of ac t i on s :− A new branch ’ f e a tu r e /mafonction2 ’ was created , based on ’ develop ’− You are now on branch ’ f e a tu r e /mafonction1 ’
Now, s t a r t committing on your f e a tu r e . When done , use :
g i t f low f ea tu r e f i n i s h mafonction2
13
Développement d’une fonctionnalité 2
Pour faire simple, on ajoute un fichier...~/demo$ touch fonct ion2 . t x t~/demo$ g i t add fonct ion2 . t x t~/demo$ g i t commit −m ”Fonction 2”[ f e a tu r e /mafonction2 2bdb068 ] Fonction 21 f i l e changed , 0 i n s e r t i o n s (+) , 0 d e l e t i o n s (−)c r ea te mode 100644 fonct ion2 . t x t
14
Finalisation de la fonctionnalité 1
Se placer dans la branche adéquate~/demo$ g i t checkout f ea tu r e /mafonction1Basculement sur l a branche ’ f e a tu r e /mafonction1 ’
Fermer la branche et l’intégrer dans develop~/demo$ g i t f low f ea tu r e f i n i s h mafonction1Basculement sur l a branche ’ develop ’Mise a jou r f e 78 f f 5 . . 6 a44a23Fast−forwardfonct ion1 . t x t | 01 f i l e changed , 0 i n s e r t i o n s (+) , 0 d e l e t i o n s (−)c r ea te mode 100644 fonct ion1 . t x tBranche f ea tu r e /mafonction1 supprimee (precedemment f2c2d2b ) .
Summary of ac t i on s :− The f ea tu r e branch ’ f e a tu r e /mafonction1 ’ was merged in to ’ develop ’− Feature branch ’ f e a tu r e /mafonction1 ’ has been l o c a l l y de l e t ed− You are now on branch ’ develop ’
15
Reprise de la fonctionnalité 2
Se placer dans la branche adéquate~/demo$ g i t checkout f ea tu r e / fonct ion2Basculement sur l a branche ’ f e a tu r e / fonct ion2 ’
Intégrer les autres développements (facultatif)~/demo$ g i t merge developMerge made by the ’ r e cu r s i v e ’ s t r a t egy .fonct ion1 . t x t | 01 f i l e changed , 0 i n s e r t i o n s (+) , 0 d e l e t i o n s (−)c r ea te mode 100644 fonct ion1 . t x t
16
Partager la fonctionnalité 2 (non-finalisée) avec l’équipe
Se placer dans la branche adéquate~/demo$ g i t checkout f ea tu r e / fonct ion2Basculement sur l a branche ’ f e a tu r e / fonct ion2 ’
Publier la branche~/demo$ g i t f low f ea tu r e pub l i sh mafonction2Decompte des ob j e t s : 9 , f a i t .Delta compress ion us ing up to 4 threads .Compression des ob j e t s : 100% (5/5) , f a i t .E c r i t u r e des ob j e t s : 100% (9/9) , 792 bytes | 0 bytes /s , f a i t .Total 9 ( de l t a 1) , reused 0 ( de l t a 0)To maforge . f r /demo . g i t* [ new branch ] f e a tu r e /mafonction2 −> fea tu r e /mafonction2
Deja sur ’ f e a tu r e /mafonction2 ’Votre branche e s t a jou r avec ’ o r i g i n / f ea tu r e /mafonction2 ’ .
Summary of ac t i on s :− A new remote branch ’ f e a tu r e /mafonction2 ’ was created− The l o c a l branch ’ f e a tu r e /mafonction2 ’ was conf igured to t rack the remote branch− You are now on branch ’ f e a tu r e /mafonction2 ’ 17
Création d’une livraison 1
Se placer dans develop~/demo$ g i t checkout developBasculement sur l a branche ’ develop ’
Créer la branche de release 1~/demo$ g i t f low r e l e a s e s t a r t marelease1Basculement sur l a nouve l l e branche ’ r e l e a s e /marelease1 ’
Summary of ac t i on s :− A new branch ’ r e l e a s e /marelease1 ’ was created , based on ’ develop ’− You are now on branch ’ r e l e a s e /marelease1 ’
Follow−up ac t i on s :− Bump the ve r s i on number now!− Star t committing l a s t−minute f i x e s in prepar ing your r e l e a s e− When done , run :
g i t f low r e l e a s e f i n i s h ’ marelease1 ’
18
Fignolage de la release (facultatif)
Ah, on a oublié le fichier de changelog...~/demo$ touch changelog . t x t~/demo$ g i t add changelog . t x t~/demo$ g i t commit −m ”changelog”[ r e l e a s e /marelease1 cc157fa ] changelog1 f i l e changed , 0 i n s e r t i o n s (+) , 0 d e l e t i o n s (−)c r ea te mode 100644 changelog . t x t
19
Fermeture de la release
~/demo$ g i t f low r e l e a s e f i n i s h marelease1Basculement sur l a branche ’master ’Merge made by the ’ r e cu r s i v e ’ s t r a t egy .changelog . t x t | 0fonct ion1 . t x t | 02 f i l e s changed , 0 i n s e r t i o n s (+) , 0 d e l e t i o n s (−)c r ea te mode 100644 changelog . t x tc r ea te mode 100644 fonct ion1 . t x t
Basculement sur l a branche ’ develop ’Merge made by the ’ r e cu r s i v e ’ s t r a t egy .changelog . t x t | 01 f i l e changed , 0 i n s e r t i o n s (+) , 0 d e l e t i o n s (−)c r ea te mode 100644 changelog . t x t
Branche r e l e a s e /marelease1 supprimee ( precedemment cc157fa ) .
Summary of ac t i on s :− Release branch ’ r e l e a s e /marelease1 ’ has been merged in to ’master ’− The r e l e a s e was tagged ’ tag/marelease1 ’− Release tag ’ tag/marelease1 ’ has been back−merged in to ’ develop ’− Release branch ’ r e l e a s e /marelease1 ’ has been l o c a l l y de l e t ed− You are now on branch ’ develop ’ 20
Publication des tags (facultatif)
~/demo$ g i t push −−tagsDecompte des ob j e t s : 4 , f a i t .Delta compress ion us ing up to 4 threads .Compression des ob j e t s : 100% (4/4) , f a i t .E c r i t u r e des ob j e t s : 100% (4/4) , 514 bytes | 0 bytes /s , f a i t .Total 4 ( de l t a 1) , reused 0 ( de l t a 0)To maforge . f r /demo . g i t* [ new tag ] tag/marelease1 −> tag/marelease1
21
Création d’une correction sur release1
Se placer dans master~/demo$ g i t checkout masterBasculement sur l a branche ’master ’
Créer la branche de hotfix 1.1~/demo$ g i t f low ho t f i x s t a r t marelease1 .1Basculement sur l a nouve l l e branche ’ h o t f i x /marelease1 .1 ’
Summary of ac t i on s :− A new branch ’ h o t f i x /marelease1 .1 ’ was created , based on ’master ’− You are now on branch ’ h o t f i x /marelease1 .1 ’
Follow−up ac t i on s :− Bump the ve r s i on number now!− Star t committing your hot f i x e s− When done , run :
g i t f low ho t f i x f i n i s h ’ marelease1 .1 ’
22
Résolution du problème
Ah, on a oublié de remplir le fichier de changelog...~/demo$ echo ’ tagada ’ > changelog . t x t~/demo$ g i t add changelog . t x t~/demo$ g i t commit −m ”changelog”[ h o t f i x /marelease1 .1 c2 fe f92 ] changelog1 f i l e changed , 1 i n s e r t i o n (+)
23
Fermeture du hotfix
~/demo$ g i t f low ho t f i x f i n i s h marelease1 .1Basculement sur l a branche ’master ’Merge made by the ’ r e cu r s i v e ’ s t r a t egy .changelog . t x t | 1 +1 f i l e changed , 1 i n s e r t i o n (+)
Basculement sur l a branche ’ develop ’Merge made by the ’ r e cu r s i v e ’ s t r a t egy .changelog . t x t | 1 +1 f i l e changed , 1 i n s e r t i o n (+)
Branche ho t f i x /marelease1 .1 supprimee ( precedemment c2 fe f92 ) .
Summary of ac t i on s :− Hotf i x branch ’ h o t f i x /marelease1 .1 ’ has been merged in to ’master ’− The ho t f i x was tagged ’ tag/marelease1 .1 ’− Hotf i x tag ’ tag/marelease1 .1 ’ has been back−merged in to ’ develop ’− Hotf i x branch ’ h o t f i x /marelease1 .1 ’ has been l o c a l l y de l e t ed− You are now on branch ’ develop ’
24
Bilan
Retour d’expérience
Positif
• facile à mettre en oeuvre (sur un projet vide)• apporte une certaine rigueur dans la gestion du projet• clarifie le nommage des branches et tags• extension qui ne se substitue pas à la richesse de Git• favorise l’usage des branches (dont il faut user et abuser avec Git !)
Négatif
• quelques pièges de config si master n’est pas préalablement initialisée• reconfig nécessaire des dépôts existants (migrer master en develop)• processus de release un peu lourd pour les cas simples sans fignolage• n’empêche pas les dérives (commit sauvage dans master ou develop)
25
Questions ?
25