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

Learning Git with Workflows

D16bc1f94b17ddc794c2dfb48ef59456?s=47 Mosky
December 27, 2013

Learning Git with Workflows

Learn Git with workflows. It is the slides for SITCON[1] 2013 Workshop[2]: "Git - The Version Control System You Must Know".

[1]: http://sitcon.org/
[2]: http://www.openfoundry.org/tw/activities/details/415-the-open-source-way-coder

D16bc1f94b17ddc794c2dfb48ef59456?s=128

Mosky

December 27, 2013
Tweet

Transcript

  1. Learning Git with Workflows Mosky

  2. This slides 2

  3. This slides won't explain every options of Git commands; and

    the internal of Git. 2
  4. This slides won't explain every options of Git commands; and

    the internal of Git. will let you start to use Git immediately; and learn the common Git workflows. 2
  5. Mosky 3

  6. Mosky A Python engineer at Pinkoi 3

  7. Mosky A Python engineer at Pinkoi An author of some

    Python packages MoSQL, Clime, ... 3
  8. Mosky A Python engineer at Pinkoi An author of some

    Python packages MoSQL, Clime, ... A speaker at several conferences PyCon APAC 2013, COSCUP 2013, PyCon TW 2013, ... 3
  9. Mosky A Python engineer at Pinkoi An author of some

    Python packages MoSQL, Clime, ... A speaker at several conferences PyCon APAC 2013, COSCUP 2013, PyCon TW 2013, ... A Python trainer 3
  10. Mosky A Python engineer at Pinkoi An author of some

    Python packages MoSQL, Clime, ... A speaker at several conferences PyCon APAC 2013, COSCUP 2013, PyCon TW 2013, ... A Python trainer http://mosky.tw/ 3
  11. None
  12. None
  13. None
  14. Outline 6

  15. Outline Setup Git 6

  16. Outline Setup Git Routine Core Secondary 6

  17. Outline Setup Git Routine Core Secondary Branching 6

  18. Outline Setup Git Routine Core Secondary Branching Remote Repository 6

  19. Outline Setup Git Routine Core Secondary Branching Remote Repository A

    Co-working Workflow 6
  20. Setup Git

  21. Get Git! 8

  22. Get Git! Ubuntu, Debian or any APT-based Linux $ sudo

    apt-get install git-core 8
  23. Get Git! Ubuntu, Debian or any APT-based Linux $ sudo

    apt-get install git-core Mac $ brew install git http://brew.sh/ 8
  24. Get Git! Ubuntu, Debian or any APT-based Linux $ sudo

    apt-get install git-core Mac $ brew install git http://brew.sh/ Windows http://git-scm.com/download/win 8
  25. Is Git there? 9

  26. GUIs are available 10

  27. GUIs are available Thanks GitHub! 10

  28. GUIs are available Thanks GitHub! "Github for Mac" http://mac.github.com/ 10

  29. GUIs are available Thanks GitHub! "Github for Mac" http://mac.github.com/ "Github

    for Windows" http://windows.github.com/ 10
  30. GUIs are available Thanks GitHub! "Github for Mac" http://mac.github.com/ "Github

    for Windows" http://windows.github.com/ Other http://git-scm.com/downloads/guis 10
  31. Tell Git who you are 11

  32. Tell Git who you are $ git config --global user.name

    "Mosky Liu" 11
  33. Tell Git who you are $ git config --global user.name

    "Mosky Liu" $ git config --global user.email mosky.tw@gmail.com 11
  34. Other Git configs 12

  35. Other Git configs $ git config --global core.editor emacs 12

  36. Other Git configs $ git config --global core.editor emacs $

    git config --global merge.tool vimdiff 12
  37. Other Git configs $ git config --global core.editor emacs $

    git config --global merge.tool vimdiff $ git config --list 12
  38. Other Git configs $ git config --global core.editor emacs $

    git config --global merge.tool vimdiff $ git config --list $ vim ~/.gitconfig 12
  39. Other Git configs $ git config --global core.editor emacs $

    git config --global merge.tool vimdiff $ git config --list $ vim ~/.gitconfig http://j.mp/mosky-gitconfig 12
  40. Core Routine

  41. Create a repository 14

  42. Create a repository $ git init [<directory>] 14

  43. Commit changes 15

  44. Commit changes $ git add <file> ... 15

  45. Commit changes $ git add <file> ... $ git commit

    15
  46. Simplest Workflow 16

  47. Simplest Workflow (1) $ git init <directory> 16

  48. Simplest Workflow (1) $ git init <directory> (2) (modify file)

    16
  49. Simplest Workflow (1) $ git init <directory> (2) (modify file)

    (3) $ git add <file> ... 16
  50. Simplest Workflow (1) $ git init <directory> (2) (modify file)

    (3) $ git add <file> ... (4) $ git commit 16
  51. Simplest Workflow (1) $ git init <directory> (2) (modify file)

    (3) $ git add <file> ... (4) $ git commit # Back 2 16
  52. Simplest Workflow (1) $ git init <directory> (2) (modify file)

    (3) $ git add <file> ... (4) $ git commit # Back 2 The end of the core --- it's super easy! 16
  53. Secondary Routine

  54. Check status of files 18

  55. Check status of files $ git status 18

  56. Check status of files $ git status 18

  57. Check what you changed 19

  58. Check what you changed $ git diff 19

  59. Check what you changed $ git diff 19

  60. Check commits 20

  61. Check commits $ git log 20

  62. Check commits $ git log 20

  63. Move between commits 21

  64. Move between commits $ git checkout <commit> 21

  65. Move between commits $ git checkout <commit> <commit> 599d439fd3813298da16f12ed40f3a0 716872c30

    599d439 HEAD 21
  66. Name commit 22

  67. Name commit $ git tag <tagname> $ git checkout 599d439

    $ git tag v0.1 $ git checkout v0.1 22
  68. Reset to a commit 23

  69. Reset to a commit $ git reset <commit> Reset HEAD

    to <commit>. 23
  70. Make a "reverse" commit 24

  71. Make a "reverse" commit $ git revert <commit> Apply a

    "reverse" commit. 24
  72. Reset to a commit 25

  73. Reset to a commit 26

  74. Make a "reverse" commit 27

  75. Make a "reverse" commit 28

  76. Branching

  77. None
  78. None
  79. None
  80. None
  81. None
  82. None
  83. None
  84. None
  85. master

  86. master topic

  87. master topic HEAD

  88. master topic HEAD

  89. master topic HEAD

  90. master topic HEAD

  91. master topic HEAD

  92. Create a branch 32

  93. Create a branch $ git branch <branchname> 32

  94. Create a branch $ git branch <branchname> $ git checkout

    <branchname> 32
  95. Create a branch $ git branch <branchname> $ git checkout

    <branchname> or 32
  96. Create a branch $ git branch <branchname> $ git checkout

    <branchname> or $ git checkout -b <branchname> 32
  97. Delete and list branch(es) 33

  98. Delete and list branch(es) $ git branch -d <branchname> Delete

    branch. 33
  99. Delete and list branch(es) $ git branch -d <branchname> Delete

    branch. $ git branch List branches. 33
  100. Move between branches 34

  101. Move between branches $ git checkout <branchname> 34

  102. Merge a branch back 35

  103. Merge a branch back $ git checkout <base-branch> 35

  104. Merge a branch back $ git checkout <base-branch> $ git

    merge <topic-branch> 35
  105. None
  106. Branching Workflow 37

  107. Branching Workflow ... 37

  108. Branching Workflow ... (1) $ git branch <topic-branch> 37

  109. Branching Workflow ... (1) $ git branch <topic-branch> (2) $

    git checkout <topic-branch> 37
  110. Branching Workflow ... (1) $ git branch <topic-branch> (2) $

    git checkout <topic-branch> (3) (modify file) 37
  111. Branching Workflow ... (1) $ git branch <topic-branch> (2) $

    git checkout <topic-branch> (3) (modify file) ... 37
  112. Branching Workflow ... (1) $ git branch <topic-branch> (2) $

    git checkout <topic-branch> (3) (modify file) ... (4) $ git commit 37
  113. Branching Workflow ... (1) $ git branch <topic-branch> (2) $

    git checkout <topic-branch> (3) (modify file) ... (4) $ git commit # Back 3 until finish "topic" 37
  114. Branching Workflow ... (1) $ git branch <topic-branch> (2) $

    git checkout <topic-branch> (3) (modify file) ... (4) $ git commit # Back 3 until finish "topic" (5) $ git checkout <base-branch> 37
  115. Branching Workflow ... (1) $ git branch <topic-branch> (2) $

    git checkout <topic-branch> (3) (modify file) ... (4) $ git commit # Back 3 until finish "topic" (5) $ git checkout <base-branch> (6) $ git merge <topic-branch> 37
  116. Remote Repository

  117. Clone a remote repository 39

  118. Clone a remote repository $ git clone <repos> <dir> 39

  119. Clone a remote repository $ git clone <repos> <dir> <repos>

    https:// github.com/torvalds/linux.git 39
  120. Create a remote repository 40

  121. Create a remote repository $ git init --bare 40

  122. Create a remote repository $ git init --bare or 40

  123. Create a remote repository $ git init --bare or https://github.com/repositories/new

    40
  124. Add, remove and list remotes 41

  125. Add, remove and list remotes $ git remote add <name>

    <url> <url> can be a local path. 41
  126. Add, remove and list remotes $ git remote add <name>

    <url> <url> can be a local path. $ git remote remove <name> 41
  127. Add, remove and list remotes $ git remote add <name>

    <url> <url> can be a local path. $ git remote remove <name> $ git remote 41
  128. Push commits to remote 42

  129. Push commits to remote $ git push <repos> <refspec>... 42

  130. Push commits to remote $ git push <repos> <refspec>... <refspec>

    usually is branch or tag name [+]<src>[:<dst>] :<dst> to delete remote reference. 42
  131. Pull commits from remote 43

  132. Pull commits from remote $ git pull <repos> <refspec>... 43

  133. A Co-working Workflow

  134. Three Principles 45

  135. Three Principles 1. master is production. 45

  136. Three Principles 1. master is production. 2. dev only includes

    stable and reviewed code. 45
  137. Three Principles 1. master is production. 2. dev only includes

    stable and reviewed code. 3. Create topic branch to resolve issue all the time. 45
  138. Three Phases 46

  139. Three Phases 1. Resolving Create a topic branch to resolve

    issue. 46
  140. Three Phases 1. Resolving Create a topic branch to resolve

    issue. 2. Reviewing Review the code. 46
  141. Three Phases 1. Resolving Create a topic branch to resolve

    issue. 2. Reviewing Review the code. 3. Cleanup Merge into dev and remove topic branch. 46
  142. 47

  143. Assigner: "We need to resolve this issue." 47

  144. Assigner: "We need to resolve this issue." Assignee: "Yes, sir!"

    47
  145. Assigner: "We need to resolve this issue." Assignee: "Yes, sir!"

    Assignee (dev) $ git checkout -b topic 47
  146. Assigner: "We need to resolve this issue." Assignee: "Yes, sir!"

    Assignee (dev) $ git checkout -b topic Assignee (topic) $ (commit...) 47
  147. Assigner: "We need to resolve this issue." Assignee: "Yes, sir!"

    Assignee (dev) $ git checkout -b topic Assignee (topic) $ (commit...) Assignee (topic) $ git push origin topic 47
  148. Assigner: "We need to resolve this issue." Assignee: "Yes, sir!"

    Assignee (dev) $ git checkout -b topic Assignee (topic) $ (commit...) Assignee (topic) $ git push origin topic Until resolve, call assigner for review. 47
  149. 48

  150. Assignee: "I resolved!" 48

  151. Assignee: "I resolved!" Assigner: "Let me review." 48

  152. Assignee: "I resolved!" Assigner: "Let me review." Assigner (dev) $

    git checkout -b topic 48
  153. Assignee: "I resolved!" Assigner: "Let me review." Assigner (dev) $

    git checkout -b topic Assigner (topic) $ git pull origin topic 48
  154. Assignee: "I resolved!" Assigner: "Let me review." Assigner (dev) $

    git checkout -b topic Assigner (topic) $ git pull origin topic Assigner (topic) $ git diff ...dev 48
  155. Assignee: "I resolved!" Assigner: "Let me review." Assigner (dev) $

    git checkout -b topic Assigner (topic) $ git pull origin topic Assigner (topic) $ git diff ...dev If it is not good enough, call assignee to fix. 48
  156. 49

  157. Assigner (topic) $ git checkout dev 49

  158. Assigner (topic) $ git checkout dev Assigner (dev) $ git

    merge topic 49
  159. Assigner (topic) $ git checkout dev Assigner (dev) $ git

    merge topic Assigner (dev) $ git push origin dev 49
  160. Assigner (topic) $ git checkout dev Assigner (dev) $ git

    merge topic Assigner (dev) $ git push origin dev Assigner: "Good job!" 49
  161. Assigner (topic) $ git checkout dev Assigner (dev) $ git

    merge topic Assigner (dev) $ git push origin dev Assigner: "Good job!" Assignee (dev) $ git branch -d topic 49
  162. Assigner (topic) $ git checkout dev Assigner (dev) $ git

    merge topic Assigner (dev) $ git push origin dev Assigner: "Good job!" Assignee (dev) $ git branch -d topic Assignee (dev) $ git push origin :topic 49
  163. Assigner (topic) $ git checkout dev Assigner (dev) $ git

    merge topic Assigner (dev) $ git push origin dev Assigner: "Good job!" Assignee (dev) $ git branch -d topic Assignee (dev) $ git push origin :topic Assignee (dev) $ git pull origin dev 49
  164. None
  165. End

  166. End 52

  167. End Use branch! 52

  168. End Use branch! Workflow does matter. 52

  169. End Use branch! Workflow does matter. Git still has many

    magics. 52
  170. End Use branch! Workflow does matter. Git still has many

    magics. Tips: http://j.mp/mosky-gitconfig 52
  171. End Use branch! Workflow does matter. Git still has many

    magics. Tips: http://j.mp/mosky-gitconfig Q&A 52