Version Control with Git, 3rd Edition

Book description

Track, branch, merge, and manage code revisions with Git, the free and open source distributed version control system. Through a series of step-by-step tutorials, this practical guide quickly takes you from Git fundamentals to advanced techniques, and provides friendly yet rigorous advice for navigating Git's many functions. You'll learn how to work with everything from small to very large projects with speed and efficiency.

In this third edition, authors Prem Kumar Ponuthorai and Jon Loeliger break down Git concepts using a modular approach. You'll start with the basics and fundamental philosophy of Git, followed by intermediate commands to help you efficiently supplement your daily development workflow. Finally, you'll learn advanced Git commands and concepts to understand how Git works under the hood.

  • Learn how to use Git for real-world development scenarios
  • Gain insight into Git's common use cases, initial tasks, and basic functions
  • Use the system for distributed version control
  • Learn how to manage merges, conflicts, patches, and diffs
  • Apply advanced techniques such as rebasing, hooks, and ways to handle submodules

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. Who This Book Is For
    2. Essential Know-How
    3. New in This Revision
    4. Navigating the Book
    5. Installing Git
    6. A Note on Inclusive Language
    7. Omissions
    8. Conventions Used in This Book
    9. O’Reilly Online Learning
    10. How to Contact Us
    11. Acknowledgments
    12. Attributions
  2. I. Thinking in Git
  3. 1. Introduction to Git
    1. Git Components
    2. Git Characteristics
    3. The Git Command Line
    4. Quick Introduction to Using Git
      1. Preparing to Work with Git
      2. Working with a Local Repository
      3. Working with a Shared Repository
      4. Configuration Files
    5. Summary
  4. 2. Foundational Concepts
    1. Repositories
      1. Git Object Store
      2. Index
      3. Content-Addressable Database
      4. Git Tracks Content
      5. Pathname Versus Content
      6. Packfiles
    2. Visualizing the Git Object Store
    3. Git Internals: Concepts at Work
      1. Inside the .git Directory
      2. Blob Objects and Hashes
      3. Tree Object and Files
      4. A Note on Git’s Use of SHA1
      5. Tree Hierarchies
      6. Commit Objects
      7. Tag Objects
    4. Summary
  5. II. Fundamentals of Git
  6. 3. Branches
    1. Motivation for Using Branches in Git
    2. Branching Guidelines
      1. Branch Names
      2. Dos and Don’ts in Branch Names
    3. Managing Branches
      1. Working in Branches
      2. Creating Branches
      3. Listing Branch Names
      4. Viewing Branches and Their Commits
      5. Switching (Checking Out) Branches
      6. Merging Changes into a Different Branch
      7. Creating and Checking Out a New Branch
      8. Detached HEAD
      9. Deleting Branches
    4. Summary
  7. 4. Commits
    1. Commits: Recorded Units of Change
    2. Atomic Changesets
    3. Identifying Commits
      1. Absolute Commit Names
      2. Refs and Symrefs
      3. Relative Commit Names
    4. Commit History
      1. Viewing Old Commits
      2. Commit Graphs
      3. Commit Ranges
    5. Summary
  8. 5. File Management and the Index
    1. Importance of the Index
    2. File Classifications in Git
    3. Using git add
    4. Notes on Using git commit
      1. Using git commit --all
      2. Writing Commit Log Messages
    5. Using git rm
    6. Using git mv
    7. A Note on Tracking Renames
    8. The .gitignore File
    9. Summary
  9. 6. Merges
    1. Merge: A Technical View
    2. Merge Examples
      1. Preparing for a Merge
      2. Merging Two Branches
      3. A Merge with a Conflict
    3. Working with Merge Conflicts
      1. Locating Conflicted Files
      2. Inspecting Conflicts
      3. How Git Keeps Track of Conflicts
      4. Finishing Up a Conflict Resolution
      5. Aborting or Restarting a Merge
    4. Merge Strategies
      1. Degenerate Merges
      2. Normal Merges
      3. Specialty Merges
      4. Applying Merge Strategies
      5. Merge Drivers
    5. How Git Thinks About Merges
      1. Merges and Git’s Object Model
      2. Squash Merges
      3. Why Not Just Merge Each Change One by One?
    6. Summary
  10. 7. Diffs
    1. Forms of the git diff Command
    2. Simple git diff Example
    3. Understanding the git diff Output
    4. git diff and Commit Ranges
    5. git diff with Path Limiting
    6. How Git Derives diffs
    7. Summary
  11. III. Intermediate Skills
  12. 8. Finding Commits
    1. Using git bisect
    2. Using git blame
    3. Using Pickaxe
    4. Summary
  13. 9. Altering Commits
    1. Philosophy of Altering Commit History
    2. Caution About Altering History
    3. Using git revert
    4. Changing the HEAD Commit
    5. Using git reset
    6. Using git cherry-pick
    7. reset, revert, and checkout
    8. Rebasing Commits
      1. Using git rebase -i
      2. rebase Versus merge
    9. Summary
  14. 10. The Stash and the Reflog
    1. The Stash
      1. Use Case: Interrupted Workflow
      2. Use Case: Updating Local Work in Progress with Upstream Changes
      3. Use Case: Converting Stashed Changes Into a Branch
    2. The Reflog
    3. Summary
  15. 11. Remote Repositories
    1. Part I: Repository Concepts
      1. Bare and Development Repositories
      2. Repository Clones
      3. Remotes
      4. Tracking Branches
      5. Referencing Other Repositories
      6. Referring to Remote Repositories
      7. The refspec
    2. Part II: Example Using Remote Repositories
      1. Creating an Authoritative Repository
      2. Make Your Own Origin Remote
      3. Developing in Your Repository
      4. Pushing Your Changes
      5. Adding a New Developer
      6. Getting Repository Updates
    3. Part III: Remote Repository Development Cycle in Pictures
      1. Cloning a Repository
      2. Alternate Histories
      3. Non-Fast-Forward Pushes
      4. Fetching the Alternate History
      5. Merging Histories
      6. Merge Conflicts
      7. Pushing a Merged History
    4. Part IV: Remote Configuration
      1. Using git remote
      2. Using git config
      3. Using Manual Editing
    5. Part V: Working with Tracking Branches
      1. Creating Tracking Branches
      2. Ahead and Behind
    6. Adding and Deleting Remote Branches
    7. Bare Repositories and git push
    8. Summary
  16. 12. Repository Management
    1. Publishing Repositories
      1. Repositories with Controlled Access
      2. Repositories with Anonymous Read Access
      3. Repositories with Anonymous Write Access
    2. Repository Publishing Advice
    3. Repository Structure
      1. Shared Repository Structure
      2. Distributed Repository Structure
    4. Living with Distributed Development
      1. Changing Public History
      2. Separate Commit and Publish Steps
      3. No One True History
    5. Knowing Your Place
      1. Upstream and Downstream Flows
      2. The Maintainer and Developer Roles
      3. Maintainer–Developer Interaction
      4. Role Duality
    6. Working with Multiple Repositories
      1. Your Own Workspace
      2. Where to Start Your Repository
      3. Converting to a Different Upstream Repository
      4. Using Multiple Upstream Repositories
      5. Forking Projects
    7. Summary
  17. IV. Advanced Skills
  18. 13. Patches
    1. Why Use Patches?
    2. Generating Patches
    3. Patches and Topological Sorts
    4. Mailing Patches
    5. Applying Patches
    6. Bad Patches
    7. Patching Versus Merging
    8. Summary
  19. 14. Hooks
    1. Types of Hooks
    2. A Note on Using Hooks
    3. Installing Hooks
      1. Example Hooks
      2. Creating Your First Hook
    4. Available Hooks
      1. Commit-Related Hooks
      2. Patch-Related Hooks
      3. Push-Related Hooks
      4. Other Local Repository Hooks
    5. To Hook or Not
    6. Summary
  20. 15. Submodules
    1. Gitlinks
    2. Submodules
      1. Why Submodules?
      2. Working with Submodules
    3. Submodules and Credential Reuse
    4. Git Subtrees
      1. Adding a Subproject
      2. Pulling Subproject Updates
      3. Changing the Subproject from Within the Superproject
    5. Git Submodule and Subtree Visual Comparison
    6. Summary
  21. 16. Advanced Manipulations
    1. Interactive Hunk Staging
    2. Loving git rev-list
      1. Date-Based Checkout
      2. Retrieve an Old Version of a File
    3. Recovering a Lost Commit
      1. The git fsck Command
      2. Reconnecting a Lost Commit
    4. Using git filter-repo
      1. Examples Using git filter-repo
    5. Summary
  22. V. Tips and Tricks
  23. 17. Tips, Tricks, and Techniques
    1. Interactive Rebase with a Dirty Working Directory
    2. Garbage Collection
    3. Tips for Recovering Commits
    4. Recovering from an Upstream Rebase
    5. Quick Overview of Changes
    6. Cleaning Up
    7. Using git-grep to Search a Repository
    8. Updating and Deleting refs
    9. Following Files That Moved
    10. Have You Been Here Before?
    11. Migrating to Git
      1. Migrating from a Git Version Control System
      2. Migrating from a Non-Git Version Control System
      3. A Note on Working with Large Repositories
    12. Git LFS
      1. Repository Before Git LFS and After Git LFS
      2. Installing Git LFS
      3. Tracking Large Objects with Git LFS
      4. Useful Git LFS Techniques
      5. Converting Existing Repositories to Use Git LFS
    13. Summary
  24. 18. Git and GitHub
    1. About GitHub
    2. Types of GitHub Accounts
    3. GitHub in the Git Ecosystem
    4. Hosting a Repository in GitHub
      1. Repository View
      2. Code
      3. Issues
      4. Pull Requests
    5. The GitHub Flow
    6. Resolving Merge Conflicts in GitHub
    7. Development Workflows
    8. Integrating with GitHub
    9. Summary
  25. A. History of Git
    1. The Birth of Git
    2. Precedents
    3. Timeline
    4. What’s in a Name?
  26. B. Installing Git
    1. Using Linux Binary Distributions
      1. Debian/Ubuntu
      2. Other Binary Distributions
    2. Installing Git on macOS
    3. Installing Git on Windows
    4. Obtaining a Source Release
    5. Building and Installing from Source Release
  27. Index
  28. About the Author

Product information

  • Title: Version Control with Git, 3rd Edition
  • Author(s): Prem Kumar Ponuthorai, Jon Loeliger
  • Release date: October 2022
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781492091196