Statistics
33
Views
0
Downloads
0
Donations
Support
Share
Uploader

高宏飞

Shared on 2026-01-05

Authorraywenderlich Tutorial Team, Jawwad Ahmad, Chris Belanger

Master Git! Chances are if you’re involved with software development you’ve heard of and have used Git at some point in your life. Version control systems are critical for any successful collaborative software project. Git is both simple to start using and accommodating for the most complex tasks with version control. Even seasoned Git users hit roadblocks on how to handle common situations. Advanced Git is here to help! This book is the easiest and fastest way to get hands-on experience with using Git for version control of your projects. Take a deep dive into: * How Git actually works: After using Git for a while it’s good to discover the whys behind all of the things. * Rebasing: Rebasing and squashing doesn’t have to be scary; it’s quite a useful and advanced way of merging code to support your collaborative workflow. * Undoing what you’ve done: Most frustration with Git comes from not being able to undo something that you’ve screwed up. But Git has lots of ways you can go back and recover from a weird merge or commit state. * Workflows in Git: Working with Git requires some rules to make sure things go smoothly across development teams. Learn the most common workflows and how to decide which one to use. * And more! One thing you can count on: after reading this book, you’ll be well-prepared to use Git in your own software development workflow!

Tags
No tags
ISBN: 1950325288
Publisher: raywenderlich.com
Publish Year: 2020
Language: 英文
Pages: 224
File Format: PDF
File Size: 6.9 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)
Advanced Git Jawwad Ahmad & Chris Belanger Copyright ©2020 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. Advanced Git raywenderlich.com 2
Dedications “For Russ and Skip.” — Chris Belanger “To my parents, my wife, and three daughters, for their support and encouragement.” — Jawwad Ahmad Advanced Git raywenderlich.com 3
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 a 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. Advanced Git raywenderlich.com 4
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 and has 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. Advanced Git raywenderlich.com 5
Table of Contents: Overview Book License 11............................................................................................. Before You Begin 12................................................................ What You Need 13........................................................................................ Book Source Code & Forums 14............................................................. About the Cover 15...................................................................................... Introduction 17.............................................................................................. Section I: Advanced Git 21.................................................... Chapter 1: How Does Git Actually Work? 22........................ Chapter 2: Merge Conflicts 32.................................................... Chapter 3: Stashes 46..................................................................... Chapter 4: Demystifying Rebasing 62...................................... Chapter 5: Rebasing to Rewrite History 80........................... Chapter 6: Gitignore After the Fact 96.................................... Chapter 7: The Many Faces of Undo 114................................ Section II: Git Workflows 135.............................................. Chapter 8: Centralized Workflow 136..................................... Chapter 9: Feature Branch Workflow 155............................. Chapter 10: Gitflow Workflow 184........................................... Chapter 11: Forking Workflow 203.......................................... Conclusion 224.............................................................................................. Advanced Git raywenderlich.com 6
Table of Contents: Extended Book License 11. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Before You Begin 12. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What You Need 13. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Book Source Code & Forums 14. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . About the Cover 15. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Introduction 17. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Enter the video courses 18. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . How to read this book 18. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Section I: Advanced Git 19. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Section II: Workflows 19. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Section I: Advanced Git 21. . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 1: How Does Git Actually Work? 22. . . . . . . . . . . . . . . . . . . Everything is a hash 23. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The inner workings of Git 24. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Git object repository structure 25. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Viewing Git objects 27. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 31. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 31. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 2: Merge Conflicts 32. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is a merge conflict? 34. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Handling your first merge conflict 35. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Merging from another branch 36. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Understanding Git conflict markers 37. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Resolving merge conflicts 38. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Editing conflicts 40. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Completing the merge operation 42. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Advanced Git raywenderlich.com 7
Challenge 44. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 45. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 45. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 3: Stashes 46. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Introducing git stash 48. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Retrieving stashes 51. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Popping stashes 55. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Applying stashes 56. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Merge conflicts with stashes 58. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Challenge 60. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 60. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 61. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 4: Demystifying Rebasing 62. . . . . . . . . . . . . . . . . . . . . . . . . . Why would you rebase? 63. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What is rebasing? 63. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Creating your first rebase operation 68. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A more complex rebase 71. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Resolving errors 73. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Challenge 79. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 79. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 5: Rebasing to Rewrite History 80. . . . . . . . . . . . . . . . . . . . . Reordering commits 81. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Interactive rebasing 81. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Squashing in an interactive rebase 83. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Creating the squash commit message 84. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Reordering commits 85. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Rewording commit messages 88. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Squashing multiple commits 90. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Challenges 93. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 95. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Advanced Git raywenderlich.com 8
Where to go from here? 95. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 6: Gitignore After the Fact 96. . . . . . . . . . . . . . . . . . . . . . . . . Getting started 97. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .gitignore across branches 97. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . How Git tracking works 100. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Updating the index manually 101. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Removing files from the index 102. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Rebasing isn’t always the solution 105. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using filter-branch to rewrite history 108. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Challenge 112. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 113. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 113. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 7: The Many Faces of Undo 114. . . . . . . . . . . . . . . . . . . . . . . Working with git reset 115. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Working with the three flavors of reset 117. . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using git reflog 126. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Finding old commits 127. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using git revert 130. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 133. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 134. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Section II: Git Workflows 135. . . . . . . . . . . . . . . . . . . . . . . . . Chapter 8: Centralized Workflow 136. . . . . . . . . . . . . . . . . . . . . . . . . . When to use the centralized workflow 137. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Centralized workflow best practices 140. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Getting started 142. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 154. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 9: Feature Branch Workflow 155. . . . . . . . . . . . . . . . . . . . . . When to use the Feature Branch workflow 156. . . . . . . . . . . . . . . . . . . . . . . . . Getting started 158. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Advanced Git raywenderlich.com 9
Merging the branches into master 169. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 183. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 10: Gitflow Workflow 184. . . . . . . . . . . . . . . . . . . . . . . . . . . . . When to use Gitflow 185. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter roadmap 185. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Types of Gitflow branches 185. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Installing git-flow 188. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Initializing git-flow 190. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 202. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 11: Forking Workflow 203. . . . . . . . . . . . . . . . . . . . . . . . . . . . . Getting started 204. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A fork is simply a clone 206. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exploring the code 208. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Fixing the custom divisors bug 210. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Opening a pull request 212. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Rewinding your main branch 214. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding upstream and fetching updates 215. . . . . . . . . . . . . . . . . . . . . . . . . . . . . Fetching changes from other forks 217. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 223. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Conclusion 224. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Advanced Git raywenderlich.com 10
LBook License By purchasing Advanced Git, you have the following license: • You are allowed to use and/or modify the source code in Advanced 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 Advanced Git in as many apps as you want, but must include this attribution line somewhere inside your app: “Artwork/images/designs: from Advanced Git, available at www.raywenderlich.com”. • The source code included in Advanced Git is for your personal use only. You are NOT allowed to distribute or sell the source code in Advanced 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 11
Before You Begin This section tells you a few things you need to know before you get started, such as what you’ll need for hardware and software, where to find the project files for this book, and more. raywenderlich.com 12
iWhat You Need To follow along with this book, you’ll need the following: • Git 2.28 or later. Git is the software package you’ll use for all 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. We’ve tested this book on Git 2.28.0, but you can follow along with older versions of Git as well. raywenderlich.com 13
iiBook Source Code & Forums Book source code The materials for this book are all available in the GitHub repository here: • https://github.com/raywenderlich/agit-materials/tree/editions/1.0 You can download the entire set of materials for the book from that page. Forum We’ve also set up an official forum for the book at https:// forums.raywenderlich.com/c/books/advanced-git/. This is a great place to ask questions about the book or to submit any errors you may find. raywenderlich.com 14
iiiAbout the Cover Advanced Git While not the most elegant or agile creature, the flightless penguin should not be underestimated. Very few other animals can boast the wide adaptability of these birds. Found in both global hemispheres, penguins are both animals of the land and the sea, spending half of their lives on each. In water, they are independent, graceful swimmers and formidable hunters, feeding on fish, squid and other sea life as they swim and dive — sometimes up to depths of over 500 meters for up to 22 minutes at a time. On land — well, we know about penguins on land. Their colonies are a comical flurry of waddling, rock-hopping and belly sliding — but they are also social, gentle and maternal. raywenderlich.com 15
Like penguins, Git thrives in multiple environments and is incredibly adaptable, and its utility should not be underestimated. Though Git seems unassuming at first glance, not many other tools will allow you to leverage your work in so many environments, both independently and socially. And like these resilient birds who manage to slip and tumble, getting back up each time, Git will allow you to work knowing any mistake can be corrected. The key is just to keep waddling along. It should also be noted that both penguins and the authors of this book look great dressed in tuxedos. Advanced Git About the Cover raywenderlich.com 16
ivIntroduction There are usually two reasons a person picks up a book about Git: one, they are unusually curious about how the software works at a deeper level; or two, they’re frustrated and need something to solve their problems now. Whatever situation brought you here, welcome! I’m happy to have you onboard. I came to write this book for both of the above reasons. I am a tinkerer and hacker by nature, and I love going deep into the internals of software to see what makes them tick. But I, like you, found Git at first to be an inscrutable piece of software. My brain, which had been trained in software development through the late 1990s, found version control packages like SVN soothing, with their familiar client-server architecture, Windows shell integration, and rather straightforward, albeit heavy, processes. When I came to use Git and GitHub about seven years ago, I found it inscrutable at best; it seemed no matter which way I turned, Git was telling me I had a merge conflict, or it was merging changes from the master branch into my current branch, or quite often complaining about unstaged changes. And why was it called a “pull request”, when clearly I was trying to push my changes into the master branch? Little by little, I learned more about how Git worked; how to solve some of the common issues I encountered, and I eventually got to a point where I felt comfortable using it on a daily basis. raywenderlich.com 17
Enter the video courses In early 2017, my colleague Sam Davies created a conference talk, titled “Mastering Git”, and from that, two video courses at raywenderlich.com: “Beginning Git” and “Mastering Git”. Those two courses form the basis of this book, but it always nagged me a little that, while Sam’s video version of the material was quite pragmatic and tied nicely into using both the command line and graphical tools to solve common Git workflow problems, I always felt like there was a bit of detail missing; the kind of information that would lead a curious mind to say “I see the how, but I really want to know more about the why.” This book gives a little more background on the why: or, in other words, “Why the %^&$ did you do that to my repository, Git?!” Underneath the hood, you’ll find that Git has a rather simple and elegant architecture, which is why it scales so well to the kinds of globally distributed projects that use Git as their version control software, via GitHub, GitLab, Bitbucket, or other cloud repository management solutions. And while GUI-based Git frontends like Tower or GitHub Desktop are great at minimizing effort, they abstract you away from the actual guts of Git. That’s why this book takes a command-line-first approach, so that you’ll gain a better understanding of the various actions that Git takes to manage your repositories — and more importantly, you’ll gain a better understanding of how to fix things when Git does things that don’t seem to make much sense. How to read this book This book begins where the other Git book in our catalogue — Git Apprentice — ends. That book covered Beginning Git. In that book, the chapters take you through concepts such as cloning, staging, committing, syncing, merging, viewing logs, and more. The very first chapter is a crash course on using Git, where you’ll go through the basic Git workflow to get a handle on the how before you move into the what and the why. The chapters work with a small repository that houses a simple ToDo system based on text files that hold ideas (both good and bad) ideas for content for the website. It’s an ideal way to learn about Git without getting bogged down in a particular language or framework. Advanced Git Introduction raywenderlich.com 18
In this book, you will cover: Section I: Advanced Git If you’ve been using Git for a while, you may choose to start in this section first. If you know how to do basic staging, committing, merging and .gitignore operations, then you’ll likely be able to jump right in here. This section walks you through concepts such as merge conflicts, stashes, rebasing, rewriting history, fixing .gitignore after the fact, and more. If you’ve ever come up against a scenario where you feel you just need to delete your local repository and clone things fresh, then this section is just what you need to help you solve those sticky Git situations. Section II: Workflows This section takes a look at some common Git workflows, such as the feature branch workflow, Gitflow, a basic forking workflow, and even a centralized workflow. Because of the flexibility of Git, lots of teams have devised interesting workflows for their teams that work for them — but this doesn’t mean that there’s a single right way to manage your development. Learning by doing Above all, the best advice I can use is to work with Git: find ways to use it in your daily workflows, find ways to contribute to open-source projects that use Git to manage their repositories, and don’t be afraid to try some of the more esoteric Git commands to accomplish something. There’s little chance you’re going to screw anything up beyond repair, and most developers learn best when they inadvertently back themselves into a technical rabbit-hole — then figure out how to dig themselves out. Advanced Git Introduction raywenderlich.com 19
A note on master vs. main At the time that this book went to press, GitHub (and potentially other hosts) were proposing changing the name of the default repository branch to main, instead of master, in an attempt to use more culturally-aware language. So if you’re working through this book and realize that some repos use main as the central reference branch, don’t worry — simply use main in place of master where you need to in these commands. If the point comes when there seems to be a consensus on main vs master in the Git community, we’ll modify the book to match. I wish you all the best in your Git adventures. Time to Git going! Advanced Git Introduction raywenderlich.com 20