You are previewing Version Control with Git.
O'Reilly logo
Version Control with Git

Book Description

Version Control with Git takes you step-by-step through ways to track, merge, and manage software projects, using this highly flexible, open source version control system. Git permits virtually an infinite variety of methods for development and collaboration. Created by Linus Torvalds to manage development of the Linux kernel, it's become the principal tool for distributed version control. But Git's flexibility also means that some users don't understand how to use it to their best advantage. Version Control with Git offers tutorials on the most effective ways to use it, as well as friendly yet rigorous advice to help you navigate Git's many functions. With this book, you will:

  • Learn how to use Git in several real-world development environments

  • Gain insight into Git's common-use cases, initial tasks, and basic functions

  • Understand how to use Git for both centralized and distributed version control

  • Use Git to manage patches, diffs, merges, and conflicts

  • Acquire advanced techniques such as rebasing, hooks, and ways to handle submodules (subprojects)

  • Learn how to use Git with Subversion

Git has earned the respect of developers around the world. Find out how you can benefit from this amazing tool with Version Control with Git.

Table of Contents

  1. Version Control with Git
    1. Preface
      1. Audience
      2. Assumed Framework
      3. Book Layout and Omissions
      4. Conventions Used in This Book
      5. Using Code Examples
      6. Safari® Books Online
      7. How to Contact Us
      8. Acknowledgments
    2. 1. Introduction
      1. Background
      2. The Birth of Git
      3. Precedents
      4. Time Line
      5. What’s in a Name?
    3. 2. Installing Git
      1. Using Linux Binary Distributions
        1. Debian/Ubuntu
        2. Other Binary Distributions
      2. Obtaining a Source Release
      3. Building and Installing
      4. Installing Git on Windows
        1. Installing the Cygwin Git Package
        2. Installing Standalone Git (msysGit)
    4. 3. Getting Started
      1. The Git Command Line
      2. Quick Introduction to Using Git
        1. Creating an Initial Repository
        2. Adding a File to Your Repository
        3. Configuring the Commit Author
        4. Making Another Commit
        5. Viewing Your Commits
        6. Viewing Commit Differences
        7. Removing and Renaming Files in Your Repository
        8. Making a Copy of Your Repository
      3. Configuration Files
        1. Configuring an Alias
      4. Inquiry
    5. 4. Basic Git Concepts
      1. Basic Concepts
        1. Repositories
        2. Git Object Types
        3. Index
        4. Content-Addressable Names
        5. Git Tracks Content
        6. Pathname Versus Content
      2. Object Store Pictures
      3. Git Concepts at Work
        1. Inside the .git directory
        2. Objects, Hashes, and Blobs
        3. Files and Trees
        4. A Note on Git’s Use of SHA1
        5. Tree Hierarchies
        6. Commits
        7. Tags
    6. 5. File Management and the Index
      1. It’s All About the Index
      2. File Classifications in Git
      3. Using git add
      4. Some 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. A Detailed View of Git’s Object Model and Files
    7. 6. Commits
      1. Atomic Changesets
      2. Identifying Commits
        1. Absolute Commit Names
        2. refs and symrefs
        3. Relative Commit Names
      3. Commit History
        1. Viewing Old Commits
        2. Commit Graphs
          1. Using gitk to view the commit graph
        3. Commit Ranges
      4. Finding Commits
        1. Using git bisect
        2. Using git blame
        3. Using Pickaxe
    8. 7. Branches
      1. Reasons for Using Branches
      2. Branch Names
        1. Dos and Don’ts in Branch Names
      3. Using Branches
      4. Creating Branches
      5. Listing Branch Names
      6. Viewing Branches
      7. Checking Out Branches
        1. A Basic Example of Checking Out a Branch
        2. Checking Out When You Have Uncommitted Changes
        3. Merging Changes into a Different Branch
        4. Creating and Checking Out a New Branch
        5. Detached HEAD Branches
      8. Deleting Branches
    9. 8. Diffs
      1. Forms of the git diff Command
      2. Simple git diff Example
      3. git diff and Commit Ranges
      4. git diff with Path Limiting
      5. Comparing How Subversion and Git Derive diffs
    10. 9. Merges
      1. Merge Examples
        1. Preparing for a Merge
        2. Merging Two Branches
        3. A Merge with a Conflict
      2. Working with Merge Conflicts
        1. Locating Conflicted Files
        2. Inspecting Conflicts
          1. git diff with conflicts
          2. git log with conflicts
        3. How Git Keeps Track of Conflicts
        4. Finishing Up a Conflict Resolution
        5. Aborting or Restarting a Merge
      3. Merge Strategies
        1. Degenerate Merges
        2. Normal Merges
          1. Recursive merges
          2. Octopus merges
        3. Specialty Merges
        4. Applying Merge Strategies
        5. Merge Drivers
      4. 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?
    11. 10. Altering Commits
      1. Caution About Altering History
      2. Using git reset
      3. Using git cherry-pick
      4. Using git revert
      5. reset, revert, and checkout
      6. Changing the Top Commit
      7. Rebasing Commits
        1. Using git rebase -i
        2. rebase Versus merge
    12. 11. Remote Repositories
      1. Repository Concepts
        1. Bare and Development Repositories
        2. Repository Clones
        3. Remotes
        4. Tracking Branches
      2. Referencing Other Repositories
        1. Referring to Remote Repositories
        2. The refspec
      3. 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
          1. The fetch step
          2. The merge or rebase step
      4. Remote Repository Operations 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
      5. Adding and Deleting Remote Branches
      6. Remote Configuration
        1. git remote
        2. git config
        3. Manual Editing
      7. Bare Repositories and git push
      8. Publishing Repositories
        1. Repositories with Controlled Access
        2. Repositories with Anonymous Read Access
          1. Publishing Repositories Using git-daemon
          2. Publishing repositories using an HTTP daemon
          3. Publishing using Git and HTTP daemons
        3. Repositories with Anonymous Write Access
    13. 12. Repository Management
      1. Repository Structure
        1. The Shared Repository Structure
        2. Distributed Repository Structure
        3. Repository Structure Examples
      2. Living with Distributed Development
        1. Changing Public History
        2. Separate Commit and Publish Steps
        3. No One True History
      3. Knowing Your Place
        1. Upstream and Downstream Flows
        2. The Maintainer and Developer Roles
        3. Maintainer-Developer Interaction
        4. Role Duality
      4. 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
          1. Isn’t forking a project bad?
          2. Reconciling forks
    14. 13. Patches
      1. Why Use Patches?
      2. Generating Patches
        1. Patches and Topological Sorts
      3. Mailing Patches
      4. Applying Patches
      5. Bad Patches
      6. Patching Versus Merging
    15. 14. Hooks
      1. Installing Hooks
        1. Example Hooks
        2. Creating Your First Hook
      2. Available Hooks
        1. Commit-Related Hooks
        2. Patch-Related Hooks
        3. Push-Related Hooks
        4. Other Local Repository Hooks
    16. 15. Combining Projects
      1. The Old Solution: Partial Checkouts
      2. The Obvious Solution: Import the Code into Your Project
        1. Importing Subprojects by Copying
        2. Importing Subprojects with git pull -s subtree
        3. Submitting Your Changes Upstream
      3. The Automated Solution: Checking Out Subprojects Using Custom Scripts
      4. The Native Solution: gitlinks and git submodule
        1. gitlinks
        2. The git submodule Command
    17. 16. Using Git with Subversion Repositories
      1. Example: A Shallow Clone of a Single Branch
        1. Making Your Changes in Git
        2. Fetching Before Committing
        3. Committing Through git svn rebase
      2. Pushing, Pulling, Branching, and Merging with git svn
        1. Keeping Your Commit IDs Straight
        2. Cloning All the Branches
        3. Sharing Your Repository
        4. Merging Back into Subversion
          1. How dcommit handles merges
      3. Miscellaneous Notes on Working with Subversion
        1. svn:ignore Versus .gitignore
        2. Reconstructing the git-svn cache
    18. Index
    19. About the Author
    20. Colophon