Learning Git with Workflows

1,468 views

Published on

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

Published in: Software
1 Comment
3 Likes
Statistics
Notes
No Downloads
Views
Total views
1,468
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
25
Comments
1
Likes
3
Embeds 0
No embeds

No notes for slide

Learning Git with Workflows

  1. 1. Learning Git with Workflows Mosky
  2. 2. This slides 2
  3. 3. This slides won't explain every options of Git commands; and the internal of Git. 2
  4. 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. 5. Mosky 3
  6. 6. Mosky A Python engineer at Pinkoi 3
  7. 7. Mosky A Python engineer at Pinkoi An author of some Python packages MoSQL, Clime, ... 3
  8. 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. 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. 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. 11. Outline 6
  12. 12. Outline Setup Git 6
  13. 13. Outline Setup Git Routine Core Secondary 6
  14. 14. Outline Setup Git Routine Core Secondary Branching 6
  15. 15. Outline Setup Git Routine Core Secondary Branching Remote Repository 6
  16. 16. Outline Setup Git Routine Core Secondary Branching Remote Repository A Co-working Workflow 6
  17. 17. Setup Git
  18. 18. Get Git! 8
  19. 19. Get Git! Ubuntu, Debian or any APT-based Linux $ sudo apt-get install git-core 8
  20. 20. Get Git! Ubuntu, Debian or any APT-based Linux $ sudo apt-get install git-core Mac $ brew install git http://brew.sh/ 8
  21. 21. 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
  22. 22. Is Git there? 9
  23. 23. GUIs are available 10
  24. 24. GUIs are available Thanks GitHub! 10
  25. 25. GUIs are available Thanks GitHub! "Github for Mac" http://mac.github.com/ 10
  26. 26. GUIs are available Thanks GitHub! "Github for Mac" http://mac.github.com/ "Github for Windows" http://windows.github.com/ 10
  27. 27. 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
  28. 28. Tell Git who you are 11
  29. 29. Tell Git who you are $ git config --global user.name "Mosky Liu" 11
  30. 30. Tell Git who you are $ git config --global user.name "Mosky Liu" $ git config --global user.email mosky.tw@gmail.com 11
  31. 31. Other Git configs 12
  32. 32. Other Git configs $ git config --global core.editor emacs 12
  33. 33. Other Git configs $ git config --global core.editor emacs $ git config --global merge.tool vimdiff 12
  34. 34. Other Git configs $ git config --global core.editor emacs $ git config --global merge.tool vimdiff $ git config --list 12
  35. 35. Other Git configs $ git config --global core.editor emacs $ git config --global merge.tool vimdiff $ git config --list $ vim ~/.gitconfig 12
  36. 36. 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
  37. 37. Core Routine
  38. 38. Create a repository 14
  39. 39. Create a repository $ git init [<directory>] 14
  40. 40. Commit changes 15
  41. 41. Commit changes $ git add <file> ... 15
  42. 42. Commit changes $ git add <file> ... $ git commit 15
  43. 43. Simplest Workflow 16
  44. 44. Simplest Workflow (1) $ git init <directory> 16
  45. 45. Simplest Workflow (1) $ git init <directory> (2) (modify file) 16
  46. 46. Simplest Workflow (1) $ git init <directory> (2) (modify file) (3) $ git add <file> ... 16
  47. 47. Simplest Workflow (1) $ git init <directory> (2) (modify file) (3) $ git add <file> ... (4) $ git commit 16
  48. 48. Simplest Workflow (1) $ git init <directory> (2) (modify file) (3) $ git add <file> ... (4) $ git commit # Back 2 16
  49. 49. 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
  50. 50. Secondary Routine
  51. 51. Check status of files 18
  52. 52. Check status of files $ git status 18
  53. 53. Check status of files $ git status 18
  54. 54. Check what you changed 19
  55. 55. Check what you changed $ git diff 19
  56. 56. Check what you changed $ git diff 19
  57. 57. Check commits 20
  58. 58. Check commits $ git log 20
  59. 59. Check commits $ git log 20
  60. 60. Move between commits 21
  61. 61. Move between commits $ git checkout <commit> 21
  62. 62. Move between commits $ git checkout <commit> <commit> 599d439fd3813298da16f12ed40f3a0 716872c30 599d439 HEAD 21
  63. 63. Name commit 22
  64. 64. Name commit $ git tag <tagname> $ git checkout 599d439 $ git tag v0.1 $ git checkout v0.1 22
  65. 65. Reset to a commit 23
  66. 66. Reset to a commit $ git reset <commit> Reset HEAD to <commit>. 23
  67. 67. Make a "reverse" commit 24
  68. 68. Make a "reverse" commit $ git revert <commit> Apply a "reverse" commit. 24
  69. 69. Reset to a commit 25
  70. 70. Reset to a commit 26
  71. 71. Make a "reverse" commit 27
  72. 72. Make a "reverse" commit 28
  73. 73. Branching
  74. 74. master
  75. 75. master topic
  76. 76. HEAD master topic
  77. 77. HEAD master topic
  78. 78. master topic HEAD
  79. 79. master topic HEAD
  80. 80. master topic HEAD
  81. 81. Create a branch 32
  82. 82. Create a branch $ git branch <branchname> 32
  83. 83. Create a branch $ git branch <branchname> $ git checkout <branchname> 32
  84. 84. Create a branch $ git branch <branchname> $ git checkout <branchname> or 32
  85. 85. Create a branch $ git branch <branchname> $ git checkout <branchname> or $ git checkout -b <branchname> 32
  86. 86. Delete and list branch(es) 33
  87. 87. Delete and list branch(es) $ git branch -d <branchname> Delete branch. 33
  88. 88. Delete and list branch(es) $ git branch -d <branchname> Delete branch. $ git branch List branches. 33
  89. 89. Move between branches 34
  90. 90. Move between branches $ git checkout <branchname> 34
  91. 91. Merge a branch back 35
  92. 92. Merge a branch back $ git checkout <base-branch> 35
  93. 93. Merge a branch back $ git checkout <base-branch> $ git merge <topic-branch> 35
  94. 94. Branching Workflow 37
  95. 95. Branching Workflow ... 37
  96. 96. Branching Workflow ... (1) $ git branch <topic-branch> 37
  97. 97. Branching Workflow ... (1) $ git branch <topic-branch> (2) $ git checkout <topic-branch> 37
  98. 98. Branching Workflow ... (1) $ git branch <topic-branch> (2) $ git checkout <topic-branch> (3) (modify file) 37
  99. 99. Branching Workflow ... (1) $ git branch <topic-branch> (2) $ git checkout <topic-branch> (3) (modify file) ... 37
  100. 100. Branching Workflow ... (1) $ git branch <topic-branch> (2) $ git checkout <topic-branch> (3) (modify file) ... (4) $ git commit 37
  101. 101. Branching Workflow ... (1) $ git branch <topic-branch> (2) $ git checkout <topic-branch> (3) (modify file) ... (4) $ git commit # Back 3 until finish "topic" 37
  102. 102. 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
  103. 103. 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
  104. 104. Remote Repository
  105. 105. Clone a remote repository 39
  106. 106. Clone a remote repository $ git clone <repos> <dir> 39
  107. 107. Clone a remote repository $ git clone <repos> <dir> <repos> https:// github.com/torvalds/linux.git 39
  108. 108. Create a remote repository 40
  109. 109. Create a remote repository $ git init --bare 40
  110. 110. Create a remote repository $ git init --bare or 40
  111. 111. Create a remote repository $ git init --bare or https://github.com/repositories/new 40
  112. 112. Add, remove and list remotes 41
  113. 113. Add, remove and list remotes $ git remote add <name> <url> <url> can be a local path. 41
  114. 114. Add, remove and list remotes $ git remote add <name> <url> <url> can be a local path. $ git remote remove <name> 41
  115. 115. Add, remove and list remotes $ git remote add <name> <url> <url> can be a local path. $ git remote remove <name> $ git remote 41
  116. 116. Push commits to remote 42
  117. 117. Push commits to remote $ git push <repos> <refspec>... 42
  118. 118. Push commits to remote $ git push <repos> <refspec>... <refspec> usually is branch or tag name [+]<src>[:<dst>] :<dst> to delete remote reference. 42
  119. 119. Pull commits from remote 43
  120. 120. Pull commits from remote $ git pull <repos> <refspec>... 43
  121. 121. A Co-working Workflow
  122. 122. Three Principles 45
  123. 123. Three Principles 1. master is production. 45
  124. 124. Three Principles 1. master is production. 2. dev only includes stable and reviewed code. 45
  125. 125. 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
  126. 126. Three Phases 46
  127. 127. Three Phases 1. Resolving Create a topic branch to resolve issue. 46
  128. 128. Three Phases 1. Resolving Create a topic branch to resolve issue. 2. Reviewing Review the code. 46
  129. 129. 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
  130. 130. 47
  131. 131. Assigner: "We need to resolve this issue." 47
  132. 132. Assigner: "We need to resolve this issue." Assignee: "Yes, sir!" 47
  133. 133. Assigner: "We need to resolve this issue." Assignee: "Yes, sir!" Assignee (dev) $ git checkout -b topic 47
  134. 134. Assigner: "We need to resolve this issue." Assignee: "Yes, sir!" Assignee (dev) $ git checkout -b topic Assignee (topic) $ (commit...) 47
  135. 135. 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
  136. 136. 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
  137. 137. 48
  138. 138. Assignee: "I resolved!" 48
  139. 139. Assignee: "I resolved!" Assigner: "Let me review." 48
  140. 140. Assignee: "I resolved!" Assigner: "Let me review." Assigner (dev) $ git checkout -b topic 48
  141. 141. Assignee: "I resolved!" Assigner: "Let me review." Assigner (dev) $ git checkout -b topic Assigner (topic) $ git pull origin topic 48
  142. 142. 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
  143. 143. 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
  144. 144. 49
  145. 145. Assigner (topic) $ git checkout dev 49
  146. 146. Assigner (topic) $ git checkout dev Assigner (dev) $ git merge topic 49
  147. 147. Assigner (topic) $ git checkout dev Assigner (dev) $ git merge topic Assigner (dev) $ git push origin dev 49
  148. 148. Assigner (topic) $ git checkout dev Assigner (dev) $ git merge topic Assigner (dev) $ git push origin dev Assigner: "Good job!" 49
  149. 149. 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
  150. 150. 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
  151. 151. 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
  152. 152. End
  153. 153. End 52
  154. 154. End Use branch! 52
  155. 155. End Use branch! Workflow does matter. 52
  156. 156. End Use branch! Workflow does matter. Git still has many magics. 52
  157. 157. End Use branch! Workflow does matter. Git still has many magics. Tips: http://j.mp/mosky-gitconfig 52
  158. 158. End Use branch! Workflow does matter. Git still has many magics. Tips: http://j.mp/mosky-gitconfig Q&A 52

×