Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Never Commit to Master: An Introduction to Git Flow

Never Commit to Master: An Introduction to Git Flow

Oliver Davies

March 02, 2014
Tweet

More Decks by Oliver Davies

Other Decks in Technology

Transcript

  1. Me Oliver Davies Developer and Systems Administrator (Twitter, D.O., IRC)

    PHPer and Drupalista since 2007 (full time since 2010) Git user since 2010 Git Flow user since 2013 @opdavies http://dgo.to/@opdavies
  2. Git Flow is: "A collection of Git extensions to provide

    high-level repository operations for ." Vincent Driessen's branching model From https://github.com/nvie/gitflow
  3. Branches m a s t e r : production code

    d e v e l o p : development code f e a t u r e / : a specific task or ticket (multiple) r e l e a s e / : temporary release branch for testing (single) h o t f i x / : temporary branch for emergency fixes s u p o r t / : experimental
  4. Why use Git Flow? Separation of production and development code

    Flexibility Better code quality Encourages collaboration Encourages peer code reviews
  5. My rules of Git Flow 1. Never, ever commit code

    directly to m a s t e r 2. Only commit stable code to d e v e l o p 3. Try not to commit directly to d e v e l o p 4. One feature branch per user story/bug 5. Commit early, commit often, push often
  6. How do I use it? CLI ~ $ b r

    e w i n s t a l l g i t - f l o w ~ $ a p t - g e t i n s t a l l g i t - f l o w ~ $ y u m i n s t a l l g i t f l o w (free, cross-platform GUI) SourceTree
  7. Need Help? ~ $ g i t f l o

    w h e l p # S h o w s t h e s t a n d a r d h e l p m e n u ~ $ g i t f l o w { s u b c o m m a n d } h e l p # S h o w s t h e h e l p m e n u f o r a s p e c i f i c s u b c o m m a n d
  8. Create your default branches ~ $ g i t f

    l o w i n i t N o b r a n c h e s e x i s t y e t . B a s e b r a n c h e s m u s t b e c r e a t e d n o w . B r a n c h n a m e f o r p r o d u c t i o n r e l e a s e s : [ m a s t e r ] B r a n c h n a m e f o r " n e x t r e l e a s e " d e v e l o p m e n t : [ d e v e l o p ]
  9. Configure branch prefixes ~ $ g i t f l

    o w i n i t N o b r a n c h e s e x i s t y e t . B a s e b r a n c h e s m u s t b e c r e a t e d n o w . B r a n c h n a m e f o r p r o d u c t i o n r e l e a s e s : [ m a s t e r ] B r a n c h n a m e f o r " n e x t r e l e a s e " d e v e l o p m e n t : [ d e v e l o p ] H o w t o n a m e y o u r s u p p o r t i n g b r a n c h p r e f i x e s ? F e a t u r e b r a n c h e s ? [ f e a t u r e / ] R e l e a s e b r a n c h e s ? [ r e l e a s e / ] H o t f i x b r a n c h e s ? [ h o t f i x / ] S u p p o r t b r a n c h e s ? [ s u p p o r t / ] V e r s i o n t a g p r e f i x ? [ ]
  10. Tip: Automatically accept the default branch names ~ $ g

    i t f l o w i n i t - d # A c c e p t s t h e d e f a u l t b r a n c h n a m e s .
  11. Features $ g i t f l o w f

    e a t u r e l i s t : lists all features c h e c k o u t : checks out an existing feature s t a r t : starts a new feature f i n i s h : finishes a feature p u b l i s h : pushes a feature into a remote repo p u l l : pulls a feature from a remote repo
  12. Start a new feature branch ~ $ g i t

    f l o w f e a t u r e s t a r t { n a m e } ~ $ g i t f l o w f e a t u r e s t a r t f o o S w i t c h e d t o a n e w b r a n c h ' f e a t u r e / f o o ' S u m m a r y o f a c t i o n s : - A n e w b r a n c h ' f e a t u r e / f o o ' w a s c r e a t e d , b a s e d o n ' d e v e l o p ' - Y o u a r e n o w o n b r a n c h ' f e a t u r e / f o o ' N o w , s t a r t c o m m i t t i n g o n y o u r f e a t u r e . W h e n d o n e , u s e : g i t f l o w f e a t u r e f i n i s h f o o
  13. Add and commit changes ~ $ d r u s

    h d l a d m i n _ m e n u ~ $ g i t a d d s i t e s / a l l / m o d u l e s / c o n t r i b / a d m i n _ m e n u ~ $ g i t c o m m i t - m " A d d e d a d m i n _ m e n u "
  14. Recommended: Rebase Your Feature Ensure that your feature is up-to-date

    ~ $ g i t f l o w f e a t u r e r e b a s e W i l l t r y t o r e b a s e ' f o o ' . . . F i r s t , r e w i n d i n g h e a d t o r e p l a y y o u r w o r k o n t o p o f i t . . . A p p l y i n g : A d d e d a d m i n _ m e n u
  15. Finish a feature ~ $ g i t f l

    o w f e a t u r e f i n i s h { n a m e } ~ $ g i t f l o w f e a t u r e f i n i s h f o o S w i t c h e d t o b r a n c h ' d e v e l o p ' U p d a t i n g 5 c 0 4 d 5 a . . 6 4 8 7 1 3 4 F a s t - f o r w a r d . . . 3 1 f i l e s c h a n g e d , 5 0 5 1 i n s e r t i o n s ( + ) D e l e t e d b r a n c h f e a t u r e / f o o ( w a s 6 4 8 7 1 3 4 ) . S u m m a r y o f a c t i o n s : - T h e f e a t u r e b r a n c h ' f e a t u r e / f o o ' w a s m e r g e d i n t o ' d e v e l o p ' - F e a t u r e b r a n c h ' f e a t u r e / f o o ' h a s b e e n r e m o v e d - Y o u a r e n o w o n b r a n c h ' d e v e l o p ' And repeat...
  16. Releases $ g i t f l o w r

    e l e a s e l i s t : lists existing releases s t a r t : starts a new release f i n i s h : finishes a release
  17. Start a new release ~ $ g i t f

    l o w r e l e a s e s t a r t { v e r s i o n } ~ $ g i t f l o w r e l e a s e s t a r t 2 0 1 4 - 0 3 - 0 2 . 0 S w i t c h e d t o a n e w b r a n c h ' r e l e a s e / 2 0 1 4 - 0 3 - 0 2 . 0 ' S u m m a r y o f a c t i o n s : - A n e w b r a n c h ' r e l e a s e / 2 0 1 4 - 0 3 - 0 2 . 0 ' w a s c r e a t e d , b a s e d o n ' d e v e l o p ' - Y o u a r e n o w o n b r a n c h ' r e l e a s e / 2 0 1 4 - 0 3 - 0 2 . 0 ' F o l l o w - u p a c t i o n s : - B u m p t h e v e r s i o n n u m b e r n o w ! - S t a r t c o m m i t t i n g l a s t - m i n u t e f i x e s i n p r e p a r i n g y o u r r e l e a s e - W h e n d o n e , r u n : g i t f l o w r e l e a s e f i n i s h ' 2 0 1 4 - 0 3 - 0 2 . 0 '
  18. Finish a release ~ $ g i t f l

    o w r e l e a s e f i n i s h { v e r s i o n } ~ $ g i t f l o w r e l e a s e f i n i s h 2 0 1 4 - 0 3 - 0 2 . 0 . . . D e l e t e d b r a n c h r e l e a s e / 2 0 1 4 - 0 3 - 0 2 . 0 ( w a s f 2 a e e 7 d ) . S u m m a r y o f a c t i o n s : - L a t e s t o b j e c t s h a v e b e e n f e t c h e d f r o m ' o r i g i n ' - R e l e a s e b r a n c h h a s b e e n m e r g e d i n t o ' m a s t e r ' - T h e r e l e a s e w a s t a g g e d ' 2 0 1 4 - 0 3 - 0 2 . 0 ' - R e l e a s e b r a n c h h a s b e e n b a c k - m e r g e d i n t o ' d e v e l o p ' - R e l e a s e b r a n c h ' r e l e a s e / 2 0 1 4 - 0 3 - 0 2 . 0 ' h a s b e e n d e l e t e d
  19. Pushing changes remotely ~ $ g i t p u

    s h - - a l l # P u s h t h e c h a n g e s t o t h e r e m o t e b r a n c h e s . ~ $ g i t p u s h - - t a g s # P u s h t h e t a g s .
  20. Tip: Finish a release in one command ~ $ g

    i t f l o w r e l e a s e f i n i s h - p m { m e s s a g e } { v e r s i o n } # S p e c i f y a c o m m i t m e s s a g e a n d a u t o m a t i c a l l y p u s h t h e c h a n g e s . ~ $ g i t f l o w r e l e a s e f i n i s h - p m 2 0 1 4 - 0 3 - 0 2 . 0 2 0 1 4 - 0 3 - 0 2 . 0
  21. finish-sprint.sh ~ $ . / f i n i s

    h - s p r i n t . s h 2 0 1 4 - 0 3 - 0 2 . 1 # ! / b i n / b a s h D R U P A L _ D I R = " / p a t h / t o / d r u p a l / d o c r o o t " T A G = $ 1 i f [ - z $ T A G ] ; t h e n # A t a g m u s t b e s p e c i f i e d . e c h o ' Y o u m u s t s p e c i f y a t a g . ' f i # G o i n t o t h e D r u p a l d i r e c t o r y c d $ D R U P A L _ D I R # S t a r t a n e w G i t F l o w r e l e a s e . g i t f l o w r e l e a s e s t a r t $ T A G - F # F l u s h t h e c a c h e . d r u s h c c a l l # E x p o r t t h e d a t a b a s e d r u s h s q l - d u m p - - g z i p - - r e s u l t - f i l e = . . / d b / $ T A G . s q l g i t a d d . . / d b / $ T A G . s q l g i t c o m m i t - m " E x p o r t e d d a t a b a s e f o r $ T A G " # F i n i s h a n d p u s h t h e r e l e a s e g i t f l o w r e l e a s e f i n i s h - p m $ T A G $ T A G
  22. Hotfixes $ g i t f l o w h

    o t f i x l i s t : list all hotfixes s t a r t : start a hotfix f i n i s h : finish a hotfix
  23. Create a new hotfix ~ $ g i t f

    l o w h o t f i x s t a r t { v e r s i o n } ~ $ g i t f l o w h o t f i x s t a r t 2 0 1 4 - 0 3 - 0 2 . 2 S w i t c h e d t o a n e w b r a n c h ' h o t f i x / 2 0 1 4 - 0 3 - 0 2 . 2 ' S u m m a r y o f a c t i o n s : - A n e w b r a n c h ' h o t f i x / 2 0 1 4 - 0 3 - 0 2 . 2 ' w a s c r e a t e d , b a s e d o n ' m a s t e r ' - Y o u a r e n o w o n b r a n c h ' h o t f i x / 2 0 1 4 - 0 3 - 0 2 . 2 ' F o l l o w - u p a c t i o n s : - B u m p t h e v e r s i o n n u m b e r n o w ! - S t a r t c o m m i t t i n g y o u r h o t f i x e s - W h e n d o n e , r u n : g i t f l o w h o t f i x f i n i s h ' 2 0 1 4 - 0 3 - 0 2 . 2 '
  24. Commit your fixes ~ $ g i t c i

    - a m ' U p d a t e d . h t a c c e s s ' [ h o t f i x / 2 0 1 4 - 0 3 - 0 2 . 2 6 d 0 4 7 3 8 ] U p d a t e d . h t a c c e s s 1 f i l e c h a n g e d , 4 i n s e r t i o n s ( + ) , 4 d e l e t i o n s ( - )
  25. Finish the hotfix ~ $ g i t f l

    o w h o t f i x f i n i s h 2 0 1 4 - 0 3 - 0 2 . 2 S w i t c h e d t o b r a n c h ' m a s t e r ' M e r g e m a d e b y t h e ' r e c u r s i v e ' s t r a t e g y . . h t a c c e s s | 8 + + + + - - - - 1 f i l e c h a n g e d , 4 i n s e r t i o n s ( + ) , 4 d e l e t i o n s ( - ) S w i t c h e d t o b r a n c h ' d e v e l o p ' M e r g e m a d e b y t h e ' r e c u r s i v e ' s t r a t e g y . . h t a c c e s s | 8 + + + + - - - - 1 f i l e c h a n g e d , 4 i n s e r t i o n s ( + ) , 4 d e l e t i o n s ( - ) D e l e t e d b r a n c h h o t f i x / 2 0 1 4 - 0 3 - 0 2 . 2 ( w a s 6 d 0 4 7 3 8 ) . S u m m a r y o f a c t i o n s : - L a t e s t o b j e c t s h a v e b e e n f e t c h e d f r o m ' o r i g i n ' - H o t f i x b r a n c h h a s b e e n m e r g e d i n t o ' m a s t e r ' - T h e h o t f i x w a s t a g g e d ' 2 0 1 4 - 0 3 - 0 2 . 2 ' - H o t f i x b r a n c h h a s b e e n b a c k - m e r g e d i n t o ' d e v e l o p ' - H o t f i x b r a n c h ' h o t f i x / 2 0 1 4 - 0 3 - 0 2 . 2 ' h a s b e e n d e l e t e d