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

Let's Learn Git

Let's Learn Git

A 20 minute dive into git.

Alina Mackenzie

March 20, 2015
Tweet

More Decks by Alina Mackenzie

Other Decks in Programming

Transcript

  1. Version control record changes revert to an earlier state tell

    a story Photo by , Flickr.com Annadriel
  2. Centralized Photo by , Flickr.com | Diagram by , git­scm.com

    Susanne Nilsson Scott Chacon and Ben Straub
  3. Distributed Photo by , Flickr.com | Diagram by , git­scm.com

    Susanne Nilsson Scott Chacon and Ben Straub
  4. Commands or app Commandline Mac, Windows, Linux, Solaris Apps SourceTree

    GitHub for SmartGit        Photo by , Flickr.com Bill Gracey
  5. Configure Scope 1. system 2. user (global) 3. directory (local)

       Photo by , Flickr.com Daniel
  6. Name and email g i t c o n f

    i g - - g l o b a l u s e r . n a m e " A l i n a M a c k e n z i e " g i t c o n f i g - - g l o b a l u s e r . e m a i l h e l l o @ a l i m . a c Photo by , Flickr.com Daniel
  7. Show configuration g i t c o n f i

    g - l u s e r . n a m e = A l i n a M a c k e n z i e u s e r . e m a i l = a l i m k n z @ g m a i l . c o m Photo by , Flickr.com Daniel
  8. Try these g i t c o n f i

    g - - g l o b a l c o l o r . u i t r u e c o r e . e x c l u d e s f i l e / U s e r s / a l i m a c / . g i t i g n o r e c o r e . w h i t e s p a c e t r a i l i n g - s p a c e Photo by , Flickr.com Daniel
  9. The setting local repository a project folder on my computer

    remote repository repository that multiple people contribute to Photo by , Flickr.com El Condor
  10. Packing list 1. packing­list 2. README.md 3. Contents of README.md

      # P a c k i n g L i s t P a c k i n g l i s t f o r t r i p s . Photo by , Flickr.com El Condor
  11. Create repository .git/ hidden folder where your repository's snapshots and

    history are stored c d p a c k i n g - l i s t g i t i n i t I n i t i a l i z e d e m p t y G i t r e p o s i t o r y i n / U s e r s / a l i m a c / p a c k i n g - l i s t / . g i t / Photo by , Flickr.com El Condor
  12. Phases Untracked Git sees it, but doesn't know about it.

    Tracked Git knows about it and tracks changes. Staged Changes are ready to be commited. Committed Changes to the file are saved to history. Pushed Changes are pushed to remote repository. Photo by , Flickr.com Luis Argerich
  13. Three sidekicks "Where am I?" "What is going on?" "What

    did I just do?" Photo by , Flickr.com christina robinson
  14. Status Where am I? g i t s t a

    t u s O n b r a n c h m a s t e r I n i t i a l c o m m i t U n t r a c k e d f i l e s : ( u s e " g i t a d d < f i l e > . . . " t o i n c l u d e i n w h a t w i l l b e c o m m i t t e d ) R E A D M E . m d n o t h i n g a d d e d t o c o m m i t b u t u n t r a c k e d f i l e s p r e s e n t ( u s e " g i t a d d " Photo by , Flickr.com christina robinson
  15. Status g i t a d d R E A

    D M E . m d g i t s t a t u s O n b r a n c h m a s t e r I n i t i a l c o m m i t C h a n g e s t o b e c o m m i t t e d : ( u s e " g i t r m - - c a c h e d < f i l e > . . . " t o u n s t a g e ) n e w f i l e : R E A D M E . m d Photo by , Flickr.com christina robinson
  16. README.md  # P a c k i n g

    L i s t P a c k i n g l i s t f o r t r i p s . * l a p t o p * s k i r t w i t h p o c k e t s * t o o t h b r u s h Photo by , Flickr.com christina robinson
  17. Status O n b r a n c h m

    a s t e r I n i t i a l c o m m i t C h a n g e s t o b e c o m m i t t e d : ( u s e " g i t r e s e t H E A D < f i l e > . . . " t o u n s t a g e ) m o d i f i e d : R E A D M E . m d C h a n g e s n o t s t a g e d f o r c o m m i t : ( u s e " g i t a d d < f i l e > . . " t o u p d a t e w h a t w i l l b e c o m m i t t e d ) ( u s e " g i t c h e c k o u t - - < f i l e > . . . " t o d i s c a r d c h a n g e s i n w o r k i n g d i r e c t o r y ) m o d i f i e d : R E A D M E . m d Photo by , Flickr.com christina robinson
  18. Diff What's going on? g i t d i f

    f d i f f - - g i t a / R E A D M E . m d b / R E A D M E . m d i n d e x d a a 8 d 6 0 . . d a 0 a 4 b 2 1 0 0 6 4 4 - - - a / R E A D M E . m d + + + b / R E A D M E . m d @ @ - 1 , 3 + 1 , 7 @ @ # P a c k i n g L i s t P a c k i n g l i s t f o r t r i p s . + + * l a p t o p + * s k i r t w i t h p o c k e t s + * t o o t h b r u s h Photo by , Flickr.com christina robinson
  19. Let's make history g i t c o m m

    i t - m " I n i t i a l c o m m i t . " [ m a s t e r ( r o o t - c o m m i t ) 1 c 5 0 e b 4 ] I n i t i a l c o m m i t . 1 f i l e c h a n g e d , 3 i n s e r t i o n s ( + ) c r e a t e m o d e 1 0 0 6 4 4 R E A D M E . m d Photo by , Flickr.com christina robinson
  20. log What just happened? g i t l o g

    c o m m i t b 9 f d 7 5 9 6 e 4 4 0 5 1 a 9 9 b 6 8 3 a 1 9 9 8 2 c 5 9 2 f d c b c a 5 a 5 A u t h o r : A l i n a M a c k e n z i e < h e l l o @ a l i m . a c > D a t e : W e d M a r 8 1 2 : 1 0 : 2 5 2 0 1 5 - 0 5 0 0 I n i t i a l c o m m i t . Photo by , Flickr.com christina robinson
  21. Commit "A set of related and reversible changes that function

    together as a unit of work." Photo by , Flickr.com Kathleen Typer­Conklin
  22. README.md  # P a c k i n g

    L i s t P a c k i n g l i s t f o r t r i p s . # # T e c h n o l o g y * l a p t o p # # C l o t h e s * s k i r t w i t h p o c k e t s # # T o i l e t r i e s * t o o t h b r u s h Photo by , Flickr.com christina robinson
  23. git add -p d i f f - - g

    i t a / R E A D M E . m d b / R E A D M E . m d i n d e x d a 0 a 4 b 2 . . 9 e 7 7 5 a 7 1 0 0 6 4 4 - - - a / R E A D M E . m d + + + b / R E A D M E . m d @ @ - 2 , 6 + 2 , 1 1 @ @ P a c k i n g l i s t f o r t r i p s . + # # T e c h n o l o g y * l a p t o p + + # # C l o t h e s * s k i r t w i t h p o c k e t s + + # # T o i l e t r i e s * t o o t h b r u s h S t a g e t h i s h u n k [ y , n , q , a , d , / , s , e , ? ] ? Photo by , Flickr.com christina robinson
  24. Split S t a g e t h i s

    h u n k [ y , n , q , a , d , / , s , e , ? ] ? s S p l i t i n t o 3 h u n k s . @ @ - 2 , 4 + 2 , 5 @ @ P a c k i n g l i s t f o r t r i p s . + # # T e c h n o l o g y * l a p t o p S t a g e t h i s h u n k [ y , n , q , a , d , / , j , J , g , e , ? ] ? Photo by , Flickr.com christina robinson
  25. Commit message g i t c o m m i

    t S h o r t d e s c r i p t i v e s u b j e c t l i n e . L o n g e r d e s c r i p t i o n i n t h e f o r m o f p a r a g r a p h s t h a t i n c l u d e r e a s o n s f o r t h e c h a n g e , r e f e r e n c e t i c k e t s o r o t h e r c o m m i t s . Photo by , Flickr.com christina robinson
  26. Push Add a remote repository Push commits to remote repository

    g i t a d d r e m o t e o r i g i n g i t @ b i t b u c k e t . o r g : a l i m a c / p a c k i n g - l i s t . g i t g i t p u s h - u o r i g i n m a s t e r Photo by , Flickr.com christina robinson
  27. Undo Not committed yet? unstage a file g i t

    r e s e t H E A D R E A D M E . m d g i t r e s e t - p undo all changes to a file g i t c h e c k o u t - - R E A D M E . m d Photo by , Flickr.com Melissa Hincha­Ownby
  28. Committed but not pushed? update last commit stage or unstage

    files as you normally would g i t c o m m i t - - a m e n d undo last commit g i t r e s e t - - s o f t H E A D ~ 1 g i t r e s e t H E A D ~ 1 (unstage, too) Photo by , Flickr.com Melissa Hincha­Ownby
  29. More than one commit? undo last 3 commits g i

    t r e s e t - - s o f t H E A D ~ 3 g i t r e s e t H E A D ~ 3 undo a specific commit g i t r e v e r t 6 1 7 f f 1 5 3 Photo by , Flickr.com Melissa Hincha­Ownby
  30. Pushed? Don't do it. But if you have to... ...

    and you are the only contributor g i t p u s h - - f o r c e < r e m o t e > < b r a n c h > Photo by , Flickr.com Melissa Hincha­Ownby
  31. Branch cheap way to create copies of the project multiple

    copies in one directory easy to merge  Photo by , Flickr.com lamoix
  32. Create branch g i t b r a n c

    h t e s t i n g Photo by , Flickr.com | Diagram by , git­scm.com lamoix Scott Chacon and Ben Straub
  33. Switch to branch g i t c h e c

    k o u t t e s t i n g Photo by , Flickr.com | Diagram by , git­scm.com lamoix Scott Chacon and Ben Straub
  34. Make commits to testing branch Photo by , Flickr.com |

    Diagram by , git­scm.com lamoix Scott Chacon and Ben Straub
  35. Switch back to master branch g i t c h

    e c k o u t m a s t e r Photo by , Flickr.com | Diagram by , git­scm.com lamoix Scott Chacon and Ben Straub
  36. Merge merge testing into master g i t c h

    e c k o u t m a s t e r g i t m e r g e t e s t i n g Photo by , Flickr.com Nige Harris
  37. Fast-forward merge Replay commits of one branch onto another Photo

    by , Flickr.com | Diagram by , git­scm.com Nige Harris Scott Chacon and Ben Straub
  38. Recursive merge Branches have diverged Photo by , Flickr.com |

    Diagram by , git­scm.com Nige Harris Scott Chacon and Ben Straub
  39. Merge commit Tie two branch endpoints Photo by , Flickr.com

    | Diagram by , git­scm.com Nige Harris Scott Chacon and Ben Straub
  40. Divergent branches Photo by , Flickr.com | Diagram by ,

    git­scm.com Nige Harris Scott Chacon and Ben Straub
  41. Rebase g i t c h e c k o

    u t e x p e r i m e n t g i t r e b a s e m a s t e r Photo by , Flickr.com | Diagram by , git­scm.com Nige Harris Scott Chacon and Ben Straub
  42. Fast-forward merge g i t c h e c k

    o u t m a s t e r g i t m e r g e e x p e r i m e n t Photo by , Flickr.com | Diagram by , git­scm.com Nige Harris Scott Chacon and Ben Straub
  43. Conflict File has been modified in the same place: 1.

    stops activity (merge, rebase) 2. lists files with conflicts 3. resolve conflicts 4. add (stage) files to continue activity     Photo by , Flickr.com Holger
  44. Conflict markers Replace text between markers with your resolution and

    delete markers. Q u e s t i o n : H o w m a n y p l a n e t s a r e t h e r e i n t h e s o l a r s y s t e m ? < < < < < < < H E A D A n s w e r : e i g h t . = = = = = = = A n s w e r : n i n e . > > > > > > > b r a n c h - a Photo by , Flickr.com Holger
  45. Resolve g i t a d d < f i

    l e > to mark conflict resolved and continue merge or rebase Q u e s t i o n : H o w m a n y p l a n e t s a r e t h e r e i n t h e s o l a r s y s t e m ? A n s w e r : e i g h t . Photo by , Flickr.com Holger
  46. Sprint Sunday 09:00-17:00 UIC SCE Tower, Room 605 750 S.

    Halsted http://2015.midcamp.org/schedule Learn through contribution Contributors of all skill sets and levels are welcome and encouraged.