Version Control with Git
by Prem Kumar Ponuthorai and Jon Loeliger
Copyright 2023 Prem Kumar Ponuthorai. All rights reserved.
Printed in the United States of America.
Published by OReilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
OReilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com .
- Acquisitions Editor: Melissa Duffield
- Development Editors: Virginia Wilson
and Shira Evans - Production Editor: Beth Kelly
- Copyeditor: Audrey Doyle
- Proofreader: Piper Editorial Consulting, LLC
- Indexer: Sue Klefstad
- Interior Designer: David Futato
- Cover Designer: Karen Montgomery
- Illustrator: Kate Dullea
- May 2009: First Edition
- August 2012: Second Edition
- November 2022: Third Edition
Revision History for the Third Edition
- 2022-10-21: First Release
See http://oreilly.com/catalog/errata.csp?isbn=9781492091196 for release details.
The OReilly logo is a registered trademark of OReilly Media, Inc. Version Control with Git, the cover image, and related trade dress are trademarks of OReilly Media, Inc.
The views expressed in this work are those of the authors, and do not represent the publishers views. While the publisher and the authors have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the authors disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
978-1-492-09119-6
[LSI]
Preface
Git is a free, open source, distributed version control system created by Linus Torvalds. Git requires low operational overhead, yet is flexible and powerful enough to support the demands of complex, large-scale, distributed software development projects.
Our goal in this book is to show you how to get the most out of Git and how to manage a Git repository with ease. By the end, you will have learned Gits philosophy, fundamental concepts, and intermediate to advanced skills for tracking content, collaborating, and managing your projects across teams.
Who This Book Is For
We wrote this book with software engineers (developers, infrastructure engineers, DevOps, etc.) in mind as our primary audience. As such, most of the concepts and examples we use relate to the daily routines and tasks of folks in the software development industry. However, Git is robust enough to track content in areas as varied as data science, graphic design, and book authoring, just to name a few. (Case in point: we used Git as our underlying versioning system to keep track of reviews and edits while writing this book!) Regardless of your title or level of proficiency, if you are using Git as your version control system, you will find value in these pages.
Essential Know-How
Prior experience with any version control system, its aims, and its goals will be a helpful foundation to understand how Git works and to build upon your knowledge as you read this book. You should have some familiarity with using any command-line tool, such as the Unix shell, along with basic knowledge of shell commands, because we use a lot of command-line instructions in the examples and discussions in the book. A general understanding of programming concepts is also a plus.
We developed the examples on the macOS and Ubuntu environments. The examples should work under other platforms such as Debian, Solaris, and Windows (using Git-installed command-line tools, such as Git for Windows), but you can expect slight variations.
Some exercises in the examples may require system-level operations that need root access on machines. Naturally, in such situations you should have a clear understanding of the responsibilities of operations that need root access.
New in This Revision
In this third edition, we take an entirely new, modular approach to the topics by breaking down the concepts of Git. We start by introducing you to the basics and the fundamental philosophy of Git, then gradually build upon intermediate commands to help you efficiently supplement your daily development workflow, and finally conclude with advanced git
commands and concepts to help you become proficient in understanding the inner mechanics of how Git works under the hood.
Another change we made in this edition was adding more illustrations to explain complex Git concepts to give you a mental model for easier comprehension. We also highlight features from the latest release of Git and provide you with examples and tips that can help improve your current distributed development workflow.
Navigating the Book
We organized this edition into categories according to the readers familiarity and experience using Git. While we categorize the sections to get progressively more advanced to incrementally build your proficiency with Git, we designed the chapters within each section so that you can leverage the content either as standalone topics or as a series of topics building on one another sequentially.
We strove to apply a consistent structure and a consistent approach to teaching concepts in every chapter. We encourage you to take a moment to internalize this format. This will help you leverage and navigate the book as a handy reference at any point in the future.
If you have picked up the book amid juggling other responsibilities and are wondering what would be the best order to hit the ground running, fret not. will help guide you toward the chapters we feel will help you gain the most knowledge in the least amount of time.
Table P-1. Categories matrix
| Thinking in Git | Fundamentals of Git | Intermediate skills | Advanced skills | Tips and tricks |
---|
Software engineering | x | x | x | x | x |
Data scientist | x | x | x | x |
Graphic designers | x | x | x |
Academia | x | x | x |
Content authors | x | x | x |
Installing Git
To reinforce the lessons taught in the book, we highly encourage you to practice the example code snippets on your development machine. To follow along with the examples, you will need Git installed on your platform of choice. Because the steps to install Git vary according to the version of your operating system, weve provided instructions on how to install Git in accordingly.
A Note on Inclusive Language
Another important point we would like to highlight about the examples is that we feel strongly about diversity and inclusion in tech, and raising awareness is a responsibility we take seriously. As a start, we will be using the word