Statistics
44
Views
0
Downloads
0
Donations
Uploader

高宏飞

Shared on 2025-12-03
Support
Share

AuthorJawwad Ahmad, Chris Belanger

No description

Tags
No tags
Publisher: Razeware LLC.
Publish Year: 2019
Language: 英文
Pages: 259
File Format: PDF
File Size: 8.3 MB
Support Statistics
¥.00 · 0times
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

(This page has no text content)
Mastering Git Jawwad Ahmad and Chris Belanger Copyright ©2019 Razeware LLC. Notice of Rights All rights reserved. No part of this book or corresponding materials (such as text, images, or source code) may be reproduced or distributed by any means without prior written permission of the copyright owner. Notice of Liability This book and all corresponding materials (such as source code) are provided on an “as is” basis, without warranty of any kind, express of implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in action of contract, tort or otherwise, arising from, out of or in connection with the software or the use of other dealing in the software. Trademarks All trademarks and registered trademarks appearing in this book are the property of their own respective owners. Mastering Git raywenderlich.com 2
About the Author Chris Belanger is an author of this book. He is the Editor-in-Chief of raywenderlich.com. If there are words to wrangle or a paragraph to ponder, he‘s on the case. In the programming world, Chris has over 25 years of experience with multiple database platforms, real- time industrial control systems, and enterprise healthcare information systems. When he kicks back, you can usually find Chris with guitar in hand, looking for the nearest beach, or exploring the lakes and rivers in his part of the world in a canoe. Jawwad Ahmad is an author of this book. He is an iOS Developer that spends way too much time using the power of Git to attempt to craft the most ideal commits. He currently works as a Software Engineer at a technology company in the San Francisco Bay Area. About the Editors Bhagat Singh is the tech editor for this book. Bhagat started iOS Development after the release of Swift, and has been fascinated by it ever since. He likes to work on making apps more usable by building great user experiences and interactions in his applications. He also is a contributor in the Raywenderlich tutorial team. When the laptop lid shuts down, you can find him chilling with his friends and finding new places to eat. He dedicates all his success to his mother. You can find Bhagat on Twitter: @soulful_swift Cesare Rocchi is a tech editor of this book. Cesare runs Studio Magnolia, an interactive studio that creates compelling web and mobile applications. He blogs at upbeat.it, and he’s also building Podrover and Affiliator You can find him on Twitter at @_funkyboy. Mastering Git raywenderlich.com 3
Manda Frederick is an editor of this book. She has been involved in publishing for over ten years through various creative, educational, medical and technical print and digital publications, and is thrilled to bring her experience to the raywenderlich.com family as Managing Editor. In her free time, you can find her at the climbing gym, backpacking in the backcountry, working on poems, playing guitar and exploring breweries. Sandra Grauschopf is an editor of this book. Sandra has over 20 years’ experience as a writer, editor, copy editor, and content manager. She’s been editing tutorials at raywenderlich.com since 2018. She loves to travel and explore new places, always with a trusty book close at hand. Aaron Douglas is the final pass editor for this book. He was that kid taking apart the mechanical and electrical appliances at five years of age to see how they worked. He never grew out of that core interest - to know how things work. He took an early interest in computer programming, figuring out how to get past security to be able to play games on his dad’s computer. He’s still that feisty nerd, but at least now he gets paid to do it. Aaron works for Automattic (WordPress.com, WooCommerce, Tumblr, SimpleNote) as a Mobile Lead primarily on the WooCommerce mobile apps. Find Aaron on Twitter as @astralbodies or at his blog at https://aaron.blog. About the Artist Vicki Wenderlich is the designer and artist of the cover of this book. She is Ray’s wife and business partner. She is a digital artist who creates illustrations, game art and a lot of other art or design work for the tutorials and books on raywenderlich.com. When she’s not making art, she loves hiking, a good glass of wine and attempting to create the perfect cheese plate. Mastering Git raywenderlich.com 4
Table of Contents: Overview Book License 13............................................................................................. What You Need 14........................................................................................ Book Source Code & Forums 15............................................................. Early Access Edition 17............................................................................... Section I: Beginning Git 18.................................................... Chapter 1: Crash Course in Git 20............................................. Chapter 2: Cloning a Repo 21...................................................... Chapter 3: Committing Your Changes 30............................... Chapter 4: The Staging Area 50.................................................. Chapter 5: Ignoring Files in Git 63............................................. Chapter 6: Git Log & History 71.................................................. Chapter 7: Branching 85................................................................ Chapter 8: Syncing with a Remote 96....................................... Chapter 9: Creating a Repository 111...................................... Chapter 10: Merging 123.............................................................. Chapter 11: Stashes 137................................................................ Section II: Advanced Git 138................................................ Chapter 12: How Does Git Actually Work? 140................... Chapter 13: Merge Conflicts 150............................................... Chapter 14: Demystifying Rebasing 163................................ Chapter 15: Rebasing to Rewrite History 181...................... Mastering Git raywenderlich.com 5
Chapter 16: Gitignore After the Fact 196............................... Chapter 17: Cherry Picking 214................................................. Chapter 18: The Many Faces of Undo 215............................. Section III: Git Workflows 236............................................. Chapter 19: Centralized Workflow 237.................................. Chapter 20: Feature Branch Workflow 256.......................... Chapter 21: Gitflow Workflow 257........................................... Chapter 22: Forking Workflow 258.......................................... Conclusion 259.............................................................................................. Mastering Git raywenderlich.com 6
Table of Contents: Extended Book License 13. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What You Need 14. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Book Source Code & Forums 15. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Early Access Edition 17. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Section I: Beginning Git 18. . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 1: Crash Course in Git 20. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 2: Cloning a Repo 21. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is cloning? 22. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using GitHub 22. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Forking 27. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 29. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 29. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 3: Committing Your Changes 30. . . . . . . . . . . . . . . . . . . . . . . What is a commit? 30. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Working trees and staging areas 34. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Committing your changes 39. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding directories 41. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Looking at Git log 45. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Challenge: Add some tutorial ideas 47. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 48. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 49. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 4: The Staging Area 50. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Why staging exists 51. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Undoing staged changes 53. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Moving files in Git 56. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Deleting files in Git 59. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Mastering Git raywenderlich.com 7
Challenge: Move, delete and restore a file 61. . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 62. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 62. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 5: Ignoring Files in Git 63. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Introducing .gitignore 64. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Getting started 64. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Nesting .gitignore files 66. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Looking at the global .gitignore 68. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Finding sample .gitignore files 68. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Challenge: Populate your local .gitignore 69. . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 69. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 70. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 6: Git Log & History 71. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Viewing Git history 71. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Vanilla git log 72. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Limiting results 72. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Graphical views of your repository 74. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Viewing non-ancestral history 76. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using Git shortlog 77. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Searching Git history 78. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Challenges 81. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 83. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 84. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 7: Branching 85. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is a commit? 86. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is a branch? 86. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Creating a branch 87. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . How Git tracks branches 87. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Checking your current branch 88. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Switching to another branch 89. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Mastering Git raywenderlich.com 8
Viewing local and remote branches 90. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Explaining origin 91. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Viewing branches graphically 92. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A shortcut for branch creation 92. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Challenge 1: Delete a branch with commits 93. . . . . . . . . . . . . . . . . . . . . . . . . . Key points 94. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 95. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 8: Syncing with a Remote 96. . . . . . . . . . . . . . . . . . . . . . . . . . . Pushing your changes 97. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Pulling changes 99. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Dealing with multiple remotes 105. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 109. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 110. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 9: Creating a Repository 111. . . . . . . . . . . . . . . . . . . . . . . . . . Getting started 112. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Creating a LICENSE file 113. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Creating a README file 115. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Creating and syncing a remote 118. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 121. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 122. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 10: Merging 123. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A look at your branches 124. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Three-way merges 125. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Merging a branch 128. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Fast-forward merge 131. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Forcing merge commits 133. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Challenge 1: Create a non-fast-forward merge 134. . . . . . . . . . . . . . . . . . . . . Key points 135. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 136. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 11: Stashes 137. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Mastering Git raywenderlich.com 9
Section II: Advanced Git 138. . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 12: How Does Git Actually Work? 140. . . . . . . . . . . . . . . . Everything is a hash 140. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The inner workings of Git 142. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Git object repository structure 143. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Viewing Git objects 145. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 149. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 149. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 13: Merge Conflicts 150. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is a merge conflict? 152. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Handling your first merge conflict 152. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Merging from another branch 153. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Understanding Git conflict markers 154. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Resolving merge conflicts 155. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Editing conflicts 157. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Completing the merge operation 159. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Challenge: Resolve another merge conflict 161. . . . . . . . . . . . . . . . . . . . . . . . . Key points 162. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 162. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 14: Demystifying Rebasing 163. . . . . . . . . . . . . . . . . . . . . . . . Why would you rebase? 164. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is rebasing? 164. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Creating your first rebase operation 169. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A more complex rebase 172. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Resolving errors 174. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Challenge 180. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 180. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 15: Rebasing to Rewrite History 181. . . . . . . . . . . . . . . . . . Reordering commits 182. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Interactive rebasing 182. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Mastering Git raywenderlich.com 10
Squashing in an interactive rebase 184. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Creating the squash commit message 185. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Reordering commits 186. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Rewording commit messages 189. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Squashing multiple commits 190. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Challenge 1: More squashing 193. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Challenge 2: Rebase your changes onto master 194. . . . . . . . . . . . . . . . . . . . . Key points 195. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 195. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 16: Gitignore After the Fact 196. . . . . . . . . . . . . . . . . . . . . . . Getting started 196. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .gitignore across branches 197. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . How Git tracking works 200. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Updating the index manually 201. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Removing files from the index 202. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Rebasing isn’t always the solution 205. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using filter-branch to rewrite history 208. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Challenge: Remove IGNORE_ME from the repository 212. . . . . . . . . . . . . . Key points 213. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 213. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 17: Cherry Picking 214. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 18: The Many Faces of Undo 215. . . . . . . . . . . . . . . . . . . . . . Working with git reset 216. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Working with the three flavors of reset 218. . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using git reflog 227. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Finding old commits 228. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using git revert 231. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 234. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 234. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Section III: Git Workflows 236. . . . . . . . . . . . . . . . . . . . . . . . Mastering Git raywenderlich.com 11
Chapter 19: Centralized Workflow 237. . . . . . . . . . . . . . . . . . . . . . . . When to use the centralized workflow 238. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Centralized workflow best practices 241. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Getting started 243. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 255. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 20: Feature Branch Workflow 256. . . . . . . . . . . . . . . . . . . . Chapter 21: Gitflow Workflow 257. . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 22: Forking Workflow 258. . . . . . . . . . . . . . . . . . . . . . . . . . . . . Conclusion 259. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Mastering Git raywenderlich.com 12
LBook License By purchasing Mastering Git, you have the following license: • You are allowed to use and/or modify the source code in Mastering Git in as many apps as you want, with no attribution required. • You are allowed to use and/or modify all art, images and designs that are included in Mastering Git in as many apps as you want, but must include this attribution line somewhere inside your app: “Artwork/images/designs: from Mastering Git, available at www.raywenderlich.com”. • The source code included in Mastering Git is for your personal use only. You are NOT allowed to distribute or sell the source code in Mastering Git without prior authorization. • This book is for your personal use only. You are NOT allowed to sell this book without prior authorization, or distribute it to friends, coworkers or students; they would need to purchase their own copies. All materials provided with this book are provided on an “as is” basis, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software. All trademarks and registered trademarks appearing in this guide are the properties of their respective owners. raywenderlich.com 13
WWhat You Need To follow along with this book, you’ll need the following: • Git 2.21.0 or later. Git is the software package that you’ll use for all of the work in this book. There are installers for macOS, Windows, and Linux available for free from the official Git page here: https://git-scm.com/downloads. raywenderlich.com 14
BBook Source Code & Forums If you bought the digital edition The digital edition of this book comes with the source code for the starter and completed projects for each chapter. These resources are included with the digital edition you downloaded from store.raywenderlich.com. If you bought the print version You can get the source code for the print edition of the book here: https://store.raywenderlich.com/products/mastering-git-source-code Forums We’ve also set up an official forum for the book at forums.raywenderlich.com. This is a great place to ask questions about the book or to submit any errors you may find. Digital book editions We have a digital edition of this book available in both ePUB and PDF, which can be handy if you want a soft copy to take with you, or you want to quickly search for a specific term within the book. Buying the digital edition version of the book also has a few extra benefits: free updates each time we update the book, access to older versions of the book, and you can download the digital editions from anywhere, at anytime. raywenderlich.com 15
Visit our book store page here: • https://store.raywenderlich.com/products/mastering-git. And if you purchased the print version of this book, you’re eligible to upgrade to the digital editions at a significant discount! Simply email support@razeware.com with your receipt for the physical copy and we’ll get you set up with the discounted digital edition version of the book. Mastering Git Book Source Code & Forums raywenderlich.com 16
EEarly Access Edition You’re reading an an early access edition of Mastering Git. This edition contains a sample of the chapters that will be contained in the final release. We hope you enjoy the preview of this book, and that you’ll come back to help us celebrate the full launch of Mastering Git early in 2020! The best way to get update notifications is to sign up for our monthly newsletter. This includes a list of the tutorials that came out on raywenderlich.com that month, any important news like book updates or new books, and a list of our favorite development links for that month. You can sign up here: • www.raywenderlich.com/newsletter raywenderlich.com 17
Section I: Beginning Git This first section is intended to get newcomers familiar with Git. It will introduce the basic concepts that are central to Git, how Git differs from other version control systems, and the basic operations of Git like committing, merging, and pulling. You may discover things in this section you didn’t quite understand about Git, even if you’ve used Git for a long time. Specifically, you’ll cover: 1. Crash Course in Git: Learn how to get started with Git, the differences between platforms, and a quick overview of the typical Git workflow. 2. Cloning a Repo: It’s quite common to start by creating a copy of somebody else’s repository. Discover how to clone a remote repo to your local machine, and what constitutes "forking" a repository. 3. Committing Your Changes: A Git repo is made up of a sequence of commits— each representing the state of your code at a point in time. Discover how to create these commits to track the changes you make in your code. 4. The Staging Area: Before you can create a Git commit, you have to use the “add” command. What does it do? Discover how to use the staging area to great effect through the interactive git add command. 5. Ignoring Files in Git: Sometimes, there are things that you really don’t want to store in your source code repository. 6. Git Log & History: There’s very little point in creating a nice history of your source code if you can’t explore it. You’ll discover the versatility of the git log command—displaying branches, graphs and even filtering the history. 7. Branching: The real power in Git comes from its branching and merging model. This allows you to work on multiple things simultaneously. Discover how to manage branches, and exactly what they are in this chapter. raywenderlich.com 18
8. Syncing with a Remote: You’ve been working hard on your local copy of the Git repository, and now you want to share this with your friends. See how you can share through using remotes, and how you can use multiple remotes at the same time. 9. Creating a Repository: If you are starting a new project, and want to use Git for source control, you first need to create a new repository. 10. Merging: Branches in Git without merging would be like basketball without the hoop—fun, sure, but with very little point. In this chapter you’ll learn how you can use merging to combine the work on multiple branches back into one. 11. Stashes: Git stashes offer a great way for you to create a temporary snapshot of what you’re working on, without having to create a full-blown commit. Discover when that might be useful, and how to go about it. Mastering Git Section I: Beginning Git raywenderlich.com 19
1Chapter 1: Crash Course in Git This is an early access release of this book. Stay tuned for this chapter in a future release! raywenderlich.com 20
The above is a preview of the first 20 pages. Register to read the complete e-book.