O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Git: Mastering Version Control

Book Description

Learn everything you need to take full control of your workflow with Git with this curated Learning Path – dive in and transform the way you work

About This Book

  • Master all the basic concepts of Git to protect your code and make it easier to evolve
  • Filled with practical recipes that will teach you how to use the most advanced features of the Git system
  • Harness the full power of the Git version control system to customize Git behavior, manipulate history, integrate external tools, and explore platform shortcuts

Who This Book Is For

This learning path is for software developers who want to become proficient at using the Git version control system. A basic understanding of any version control system would be beneficial.

What You Will Learn

  • Transport your work to a remote repository in a centralized manner
  • Experiment with your code without affecting functional code files
  • Explore some tools used to migrate to Git from other versioning systems without losing your development history
  • Understand the Git data model and how you can navigate the database with simple commands
  • Debug with Git and use various techniques to find faulty commits
  • Customize Git behavior system-wide, on a per-user, per-repository, and per-file basis
  • Master administering and setting up Git repositories, configuring access, finding and recovering from repository errors, and performing repository maintenance
  • Chose a workflow and configure/set up support for the chosen workflow

In Detail

Git is one of the most popular types of Distributed Version Control System. Since its inception, it has attracted skilled developers due to its robust, powerful, and reliable features. Like most powerful tools, Git can be hard to approach for the newcomers. However, this learning path will help you overcome this fear and become adept at all the basic and advanced tasks in Git.

This course starts with an introduction to version control systems before you delve deeply into the essentials of Git. This serves as a primer for the topics to follow such as branching and merging, creating and managing a GitHub personal repository, and fork and pull requests. You'll also learn how to migrate from SVN using Git tools or TortoiseGit and migrate from other VCSs, concluding with a collection of resources, links, and appendices.

As you progress on to the next module, you will learn how you can automate the usual Git processes by utilizing the hook system built into Git. It also covers advanced repository management, including different options to rewrite the history of a Git repository before you discover how you can work offline with Git, how to track what is going on behind the scenes, and how to use the stash for different purposes.

Moving forward, you will gain deeper insights into Git's architecture, its underlying concepts, behavior, and best practices. It gives a quick implementation example of using Git for a collaborative development of a sample project to establish the foundation knowledge of Git operational tasks and concepts. By exploring advanced Git practices, you will attain a deeper understanding of Git’s behavior, allowing you to customize and extend existing recipes and write your own.

This Learning Path is a blend of content, all packaged up keeping your journey in mind. It includes content from the following Packt products:

  • Git Essentials, Ferdinando Santacroce
  • Git Version Control Cookbook, Aske Olsson and Rasmus Voss
  • Mastering Git, Jakub Narębski

Style and approach

Its step-by-step approach with useful information makes this course the ultimate guide to understanding and mastering Git. This course will show the road to mastery example by example, while also explaining the mental model of Git.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. Git: Mastering Version Control
    1. Table of Contents
    2. Git: Mastering Version Control
    3. Git: Mastering Version Control
    4. Credits
    5. Preface
      1. What this learning path covers
      2. What you need for this learning path
      3. Who this learning path is for
      4. Reader feedback
      5. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    6. I. Module 1
      1. 1. Getting Started with Git
        1. Installing Git
        2. Running our first Git command
          1. Setting up a new repository
          2. Adding a file
          3. Commit the added file
          4. Modify a committed file
        3. Summary
      2. 2. Git Fundamentals – Working Locally
        1. Repository structure and file status life cycle
          1. The working directory
            1. File statuses
          2. The staging area
            1. Unstaging a file
          3. The time metaphor
            1. The past
            2. The present
            3. The future
        2. Working with repositories
          1. Unstaging a file
        3. Viewing the history
          1. Anatomy of a commit
            1. The commit snapshot
            2. The commit hash
            3. Author, e-mail, and date
            4. Commit messages
          2. Committing a bunch of files
            1. Ignoring some files and folders by default
          3. Highlighting an important commit – Git tags
        4. Taking another way – Git branching
          1. Anatomy of branches
            1. Looking at the current branches
            2. Creating a new branch
            3. Switching from branch to branch
            4. Understanding what happens under the hood
            5. A bird's eye view to branches
            6. Typing is boring – Git aliases
          2. Merging branches
            1. Merge is not the end of the branch
          3. Exercises
            1. Exercise 2.1
              1. What you will learn
              2. Scenario
              3. Results
            2. Exercise 2.2
              1. What you will learn
              2. Scenario
              3. Results
          4. Deal with branches' modifications
            1. Diffing branches
            2. Using a visual diff tool
          5. Resolving merge conflicts
            1. Edit collisions
            2. Resolving a removed file conflict
              1. Keeping the edited file
              2. Resolving conflicts by removing the file
        5. Stashing
        6. Summary
      3. 3. Git Fundamentals – Working Remotely
        1. Working with remotes
          1. Setting up a new GitHub account
          2. Cloning a repository
          3. Uploading modifications to remotes
            1. What do I send to the remote when I push?
            2. Pushing a new branch to the remote
          4. The origin
            1. Tracking branches
          5. Downloading remote changes
            1. Checking for modifications and downloading them
            2. Applying downloaded changes
          6. Going backward: publish a local repository to GitHub
            1. Adding a remote to a local repository
            2. Pushing a local branch to a remote repository
          7. Social coding – collaborate using GitHub
            1. Forking a repository
            2. Submitting pull requests
            3. Creating a pull request
        2. Summary
      4. 4. Git Fundamentals – Niche Concepts, Configurations, and Commands
        1. Dissecting the Git configuration
          1. Configuration architecture
            1. Configuration levels
              1. System level
              2. Global level
              3. Repository level
            2. Listing configurations
            3. Editing configuration files manually
            4. Setting up other environment configurations
              1. Basic configurations
                1. Typos autocorrection
                2. Push default
                3. Defining the default editor
                4. Other configurations
        2. Git aliases
          1. Shortcuts to common commands
          2. Creating commands
            1. git unstage
            2. git undo
            3. git last
            4. git difflast
          3. Advanced aliases with external commands
          4. Removing an alias
          5. Aliasing the git command itself
        3. Git references
          1. Symbolic references
          2. Ancestry references
            1. The first parent
            2. The second parent
        4. World-wide techniques
          1. Changing the last commit message
          2. Tracing changes in a file
          3. Cherry picking
        5. Tricks
          1. Bare repositories
            1. Converting a regular repository to a bare one
          2. Backup repositories
            1. Archiving the repository
            2. Bundling the repository
        6. Summary
      5. 5. Obtaining the Most – Good Commits and Workflows
        1. The art of committing
          1. Building the right commit
            1. Make only one change per commit
              1. Split up features and tasks
              2. Write commit messages before starting to code
            2. Include the whole change in one commit
            3. Describe the change, not what you have done
            4. Don't be afraid to commit
            5. Isolate meaningless commits
            6. The perfect commit message
              1. Writing a meaningful subject
              2. Adding bulleted details lines, when needed
              3. Tie other useful information
              4. Special messages for releases
              5. Conclusions
        2. Adopting a workflow – a wise act
          1. Centralized workflows
            1. How they work
          2. Feature branch workflow
          3. GitFlow
            1. The master branch
            2. Hotfixes branches
            3. The develop branch
            4. The release branch
            5. The feature branches
            6. Conclusion
          4. The GitHub flow
            1. Anything in the master branch is deployable
            2. Creating descriptive branches off of the master
            3. Pushing to named branches constantly
            4. Opening a pull request at any time
            5. Merging only after a pull request review
            6. Deploying immediately after review
            7. Conclusions
          5. Other workflows
            1. The Linux kernel workflow
        3. Summary
      6. 6. Migrating to Git
        1. Before starting
          1. Prerequisites
        2. Working on a Subversion repository using Git
          1. Creating a local Subversion repository
          2. Checking out the Subversion repository with svn client
          3. Cloning a Subversion repository from Git
            1. Setting up a local Subversion server
          4. Adding a tag and a branch
          5. Committing a file to Subversion using Git as a client
        3. Using Git with a Subversion repository
        4. Migrating a Subversion repository
          1. Retrieving the list of Subversion users
          2. Cloning the Subversion repository
          3. Preserving the ignored file list
          4. Pushing to a local bare Git repository
          5. Arranging branches and tags
            1. Renaming the trunk branch to master
            2. Converting Subversion tags to Git tags
          6. Pushing the local repository to a remote
        5. Comparing Git and Subversion commands
        6. Summary
      7. 7. Git Resources
        1. Git GUI clients
          1. Windows
            1. Git GUI
            2. TortoiseGit
            3. GitHub for Windows
            4. Atlassian SourceTree
            5. Cmder
          2. Mac OS X
          3. Linux
        2. Building up a personal Git server with web interface
          1. The SCM Manager
        3. Learning Git in a visual manner
        4. Git on the Internet
          1. Git community on Google+
          2. GitMinutes and Thomas Ferris Nicolaisen's blog
          3. Ferdinando Santacroce's blog
        5. Summary
    7. II. Module 2
      1. 1. Navigating Git
        1. Introduction
        2. Git's objects
          1. Getting ready
          2. How to do it...
            1. The commit object
            2. The tree object
            3. The blob object
            4. The branch
            5. The tag object
          3. How it works...
          4. There's more...
          5. See also
        3. The three stages
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. See also
        4. Viewing the DAG
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. Extracting fixed issues
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        6. Getting a list of the changed files
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        7. Viewing history with Gitk
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        8. Finding commits in history
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        9. Searching through history code
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
      2. 2. Configuration
        1. Configuration targets
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        2. Querying the existing configuration
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        3. Templates
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. A .git directory template
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. A few configuration examples
          1. Getting ready
          2. How to do it...
            1. Rebase and merge setup
            2. Expiry of objects
            3. Autocorrect
          3. How it works...
          4. There's more...
        6. Git aliases
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        7. The refspec exemplified
          1. Getting ready
          2. How to do it...
          3. How it works...
      3. 3. Branching, Merging, and Options
        1. Introduction
        2. Managing your local branches
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more...
        3. Branches with remotes
          1. Getting ready
          2. How to do it…
          3. There's more...
        4. Forcing a merge commit
          1. Getting ready
          2. How to do it...
          3. There's more…
        5. Using git rerere to merge known conflicts
          1. How to do it…
          2. There's more...
        6. The difference between branches
          1. Getting ready
          2. How to do it…
          3. There's more…
      4. 4. Rebase Regularly and Interactively, and Other Use Cases
        1. Introduction
        2. Rebasing commits to another branch
          1. Getting ready
          2. How to do it…
          3. How it works
        3. Continuing a rebase with merge conflicts
          1. How to do it
          2. How it works
          3. There's more…
        4. Rebasing selective commits interactively
          1. Getting ready
          2. How to do it
          3. There's more…
        5. Squashing commits using an interactive rebase
          1. Getting ready
          2. How to do it...
          3. There's more…
        6. Changing the author of commits using a rebase
          1. Getting ready
          2. How to do it...
          3. How it works...
        7. Auto-squashing commits
          1. Getting ready
          2. How to do it...
          3. There's more…
      5. 5. Storing Additional Information in Your Repository
        1. Introduction
        2. Adding your first Git note
          1. Getting ready
          2. How to do it…
          3. There's more...
        3. Separating notes by category
          1. Getting ready
          2. How to do it...
          3. How it works...
        4. Retrieving notes from the remote repository
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Pushing notes to a remote repository
          1. How to do it...
          2. There's more...
        6. Tagging commits in the repository
          1. Getting ready
          2. How to do it...
          3. There's more...
      6. 6. Extracting Data from the Repository
        1. Introduction
        2. Extracting the top contributor
          1. Getting ready
          2. How to do it...
          3. There's more...
        3. Finding bottlenecks in the source tree
          1. Getting ready
          2. How to do it...
          3. There's more...
        4. Grepping the commit messages
          1. Getting ready
          2. How to do it...
        5. The contents of the releases
          1. How to do it...
          2. How it works...
      7. 7. Enhancing Your Daily Work with Git Hooks, Aliases, and Scripts
        1. Introduction
        2. Using a branch description in the commit message
          1. Getting ready
          2. How to do it...
        3. Creating a dynamic commit message template
          1. Getting ready
          2. How to do it...
          3. There's more...
        4. Using external information in the commit message
          1. Getting ready
          2. How to do it...
        5. Preventing the push of specific commits
          1. Getting ready
          2. How to do it...
          3. There's more...
        6. Configuring and using Git aliases
          1. How to do it...
          2. How it works...
        7. Configuring and using Git scripts
          1. How to do it...
        8. Setting up and using a commit template
          1. Getting ready
          2. How to do it...
      8. 8. Recovering from Mistakes
        1. Introduction
        2. Undo – remove a commit completely
          1. Getting ready
          2. How to do it...
          3. How it works…
        3. Undo – remove a commit and retain the changes to files
          1. Getting ready
          2. How to do it...
          3. How it works…
        4. Undo – remove a commit and retain the changes in the staging area
          1. Getting ready
          2. How to do it...
          3. How it works…
        5. Undo – working with a dirty area
          1. Getting ready
          2. How to do it...
          3. How it works…
          4. See also
        6. Redo – recreate the latest commit with new changes
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There is more…
        7. Revert – undo the changes introduced by a commit
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        8. Reverting a merge
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There is more...
          5. See also
        9. Viewing past Git actions with git reflog
          1. Getting ready
          2. How to do it...
          3. How it works...
        10. Finding lost changes with git fsck
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
      9. 9. Repository Maintenance
        1. Introduction
        2. Pruning remote branches
          1. Getting ready
          2. How to do it...
          3. How it works…
          4. There's more…
        3. Running garbage collection manually
          1. Getting ready
          2. How to do it...
          3. How it works…
        4. Turning off automatic garbage collection
          1. Getting ready
          2. How to do it...
        5. Splitting a repository
          1. Getting ready
          2. How to do it...
          3. How it works…
          4. There's more…
        6. Rewriting history – changing a single file
          1. Getting ready
          2. How to do it...
          3. How it works…
        7. Back up your repositories as mirror repositories
          1. Getting ready
          2. How to do it...
          3. How it works…
          4. There's more…
        8. A quick submodule how-to
          1. Getting ready
          2. How to do it...
          3. There's more…
        9. Subtree merging
          1. Getting ready
          2. How to do it...
          3. How it works…
          4. See also
        10. Submodule versus subtree merging
      10. 10. Patching and Offline Sharing
        1. Introduction
        2. Creating patches
          1. Getting ready
          2. How to do it...
          3. How it works…
          4. There's more…
        3. Creating patches from branches
          1. Getting ready
          2. How to do it...
          3. How it works…
          4. There's more…
        4. Applying patches
          1. Getting ready
          2. How to do it...
          3. How it works…
          4. There's more…
        5. Sending patches
          1. Getting ready
          2. How to do it...
          3. How it works…
          4. There's more…
        6. Creating Git bundles
          1. Getting ready
          2. How to do it...
          3. How it works…
        7. Using a Git bundle
          1. Getting ready
          2. How to do it…
          3. There's more…
        8. Creating archives from a tree
          1. Getting ready
          2. How to do it...
          3. There's more…
      11. 11. Git Plumbing and Attributes
        1. Introduction
        2. Displaying the repository information
          1. Getting ready
          2. How to do it...
          3. There's more…
        3. Displaying the tree information
          1. Getting ready
          2. How to do it...
        4. Displaying the file information
          1. Getting ready
          2. How to do it...
          3. There's more…
        5. Writing a blob object to the database
          1. Getting ready
          2. How to do it...
          3. How it works…
          4. There's more…
        6. Writing a tree object to the database
          1. Getting ready
          2. How to do it...
          3. How it works…
        7. Writing a commit object to the database
          1. Getting ready
          2. How to do it...
          3. How it works…
        8. Keyword expansion with attribute filters
          1. Getting ready
          2. How to do it...
          3. How it works…
          4. There's more…
        9. Metadata diff of binary files
          1. Getting ready
          2. How to do it...
          3. How it works…
          4. There's more…
        10. Storing binaries elsewhere
          1. Getting ready
          2. How to do it...
          3. How it works…
          4. There's more…
          5. See also
        11. Checking the attributes of a file
          1. Getting ready
          2. How to do it...
        12. Attributes to export an archive
          1. Getting ready
          2. How to do it...
          3. There's more…
      12. 12. Tips and Tricks
        1. Introduction
        2. Using git stash
          1. Getting ready
          2. How to do it...
          3. How it works…
          4. There's more…
        3. Saving and applying stashes
          1. Getting ready
          2. How to do it...
          3. There's more…
        4. Debugging with git bisect
          1. Getting ready
          2. How to do it...
          3. There's more…
        5. Using the blame command
          1. Getting ready
          2. How to do it...
          3. There's more…
        6. Color UI in the prompt
          1. Getting ready
          2. How to do it...
          3. There's more…
        7. Autocompletion
          1. Getting ready
            1. Linux
            2. Mac
            3. Windows
          2. How to do it...
          3. How it works…
          4. There's more…
        8. Bash prompt with status information
          1. Getting ready
          2. How to do it...
          3. How it works…
          4. There's more…
          5. See also
        9. More aliases
          1. Getting ready
          2. How to do it...
        10. Interactive add
          1. Getting ready
          2. How to do it...
          3. There's more…
        11. Interactive add with Git GUI
          1. Getting ready
          2. How to do it...
        12. Ignoring files
          1. Getting ready
          2. How to do it...
          3. There's more…
          4. See also…
        13. Showing and cleaning ignored files
          1. Getting ready
          2. How to do it...
          3. There's more…
    8. III. Module 3
      1. 1. Git Basics in Practice
        1. An introduction to version control and Git
        2. Git by example
          1. Repository setup
          2. Creating a Git repository
          3. Cloning the repository and creating the first commit
          4. Publishing changes
          5. Examining history and viewing changes
          6. Renaming and moving files
          7. Updating your repository (with merge)
          8. Creating a tag
          9. Resolving a merge conflict
          10. Adding files in bulk and removing files
          11. Undoing changes to a file
          12. Creating a new branch
          13. Merging a branch (no conflicts)
          14. Undoing an unpublished merge
        3. Summary
      2. 2. Exploring Project History
        1. Directed Acyclic Graphs
          1. Whole-tree commits
          2. Branches and tags
          3. Branch points
          4. Merge commits
        2. Single revision selection
          1. HEAD – the implicit revision
          2. Branch and tag references
          3. SHA-1 and the shortened SHA-1 identifier
          4. Ancestry references
          5. Reverse ancestry references: the git describe output
          6. Reflog shortnames
          7. Upstream of remote-tracking branches
          8. Selecting revision by the commit message
        3. Selecting the revision range
          1. Single revision as a revision range
          2. Double dot notation
          3. Multiple points – including and excluding revisions
          4. The revision range for a single revision
          5. Triple-dot notation
        4. Searching history
          1. Limiting the number of revisions
          2. Matching revision metadata
            1. Time-limiting options
            2. Matching commit contents
            3. Commit parents
          3. Searching changes in revisions
          4. Selecting types of change
        5. History of a file
          1. Path limiting
          2. History simplification
          3. Blame – the line-wise history of a file
        6. Finding bugs with git bisect
        7. Selecting and formatting the git log output
          1. Predefined and user defined output formats
          2. Including, formatting, and summing up changes
          3. Summarizing contributions
          4. Viewing a revision and a file at revision
        8. Summary
      3. 3. Developing with Git
        1. Creating a new commit
          1. The DAG view of creating a new commit
          2. The index – a staging area for commits
          3. Examining the changes to be committed
            1. The status of the working directory
            2. Examining differences from the last revision
            3. Unified Git diff format
          4. Selective commit
            1. Selecting files to commit
            2. Interactively selecting changes
            3. Creating a commit step by step
          5. Amending a commit
        2. Working with branches
          1. Creating a new branch
          2. Creating orphan branches
          3. Selecting and switching to a branch
            1. Obstacles to switching to a branch
            2. Anonymous branches
            3. Git checkout DWIM-mery
          4. Listing branches
          5. Rewinding or resetting a branch
          6. Deleting a branch
          7. Changing the branch name
        3. Summary
      4. 4. Managing Your Worktree
        1. Ignoring files
          1. Marking files as intentionally untracked
          2. Which types of file should be ignored?
          3. Listing ignored files
          4. Ignoring changes in tracked files
        2. File attributes
          1. Identifying binary files and end-of-line conversions
          2. Diff and merge configuration
            1. Generating diffs and binary files
            2. Configuring diff output
            3. Performing a 3-way merge
          3. Transforming files (content filtering)
            1. Obligatory file transformations
          4. Keyword expansion and substitution
          5. Other built-in attributes
          6. Defining attribute macros
        3. Fixing mistakes with the reset command
          1. Rewinding the branch head, softly
            1. Removing or amending a commit
            2. Squashing commits with reset
          2. Resetting the branch head and the index
            1. Splitting a commit with reset
            2. Saving and restoring state with the WIP commit
          3. Discarding changes and rewinding branch
            1. Moving commits to a feature branch
            2. Undoing a merge or a pull
          4. Safer reset – keeping your changes
            1. Rebase changes to an earlier revision
        4. Stashing away your changes
          1. Using git stash
          2. Stash and the staging area
          3. Stash internals
            1. Un-applying a stash
            2. Recovering stashes that were dropped erroneously
        5. Managing worktrees and the staging area
          1. Examining files and directories
          2. Searching file contents
          3. Un-tracking, un-staging, and un-modifying files
          4. Resetting a file to the old version
          5. Cleaning the working area
        6. Multiple working directories
        7. Summary
      5. 5. Collaborative Development with Git
        1. Collaborative workflows
          1. Bare repositories
          2. Interacting with other repositories
          3. The centralized workflow
          4. The peer-to-peer or forking workflow
          5. The maintainer or integration manager workflow
          6. The hierarchical or dictator and lieutenants workflows
        2. Managing remote repositories
          1. The origin remote
          2. Listing and examining remotes
          3. Adding a new remote
          4. Updating information about remotes
            1. Renaming remotes
            2. Changing the remote URLs
            3. Changing the list of branches tracked by remote
            4. Setting the default branch of remote
            5. Deleting remote-tracking branches
          5. Support for triangular workflows
        3. Transport protocols
          1. Local transport
          2. Smart transports
            1. Native Git protocol
            2. SSH protocol
            3. Smart HTTP(S) protocol
          3. Offline transport with bundles
            1. Cloning and updating with bundle
            2. Using bundle to update an existing repository
            3. Utilizing bundle to help with the initial clone
          4. Remote transport helpers
            1. Transport relay with remote helpers
            2. Using foreign SCM repositories as remotes
          5. Credentials/password management
            1. Asking for passwords
            2. Public key authentication for SSH
            3. Credential helpers
        4. Publishing your changes upstream
          1. Pushing to a public repository
          2. Generating a pull request
          3. Exchanging patches
        5. Chain of trust
          1. Content-addressed storage
          2. Lightweight, annotated, and signed tags
            1. Lightweight tags
            2. Annotated tags
            3. Signed tags
            4. Publishing tags
            5. Tag verification
          3. Signed commits
          4. Merging signed tags (merge tags)
        6. Summary
      6. 6. Advanced Branching Techniques
        1. Types and purposes of branches
          1. Long-running, perpetual branches
            1. Integration, graduation, or progressive-stability branches
            2. Per-release branches and per-release maintenance
            3. Hotfix branches for security fixes
            4. Per-customer or per-deployment branches
            5. Automation branches
            6. Mob branches for anonymous push access
            7. The orphan branch trick
          2. Short-lived branches
            1. Topic or feature branches
            2. Bugfix branches
            3. Detached HEAD – the anonymous branch
        2. Branching workflows and release engineering
          1. The release and trunk branches workflow
          2. The graduation, or progressive-stability branches workflow
          3. The topic branches workflow
            1. Graduation branches in a topic branch workflow
            2. Branch management for a release in a topic branch workflow
          4. Git-flow – a successful Git branching model
          5. Fixing a security issue
        3. Interacting with branches in remote repositories
          1. Upstream and downstream
          2. Remote-tracking branches and refspec
            1. Remote-tracking branches
            2. Refspec – remote to local branch mapping specification
          3. Fetching and pulling versus pushing
            1. Pull – fetch and update current branch
            2. Pushing to the current branch in a nonbare remote repository
            3. The default fetch refspec and push modes
          4. Fetching and pushing branches and tags
            1. Fetching branches
            2. Fetching tags and automatic tag following
            3. Pushing branches and tags
          5. Push modes and their use
            1. The simple push mode – the default
            2. The matching push mode for maintainers
            3. The upstream push mode for the centralized workflow
            4. The current push mode for the blessed repository workflow
        4. Summary
      7. 7. Merging Changes Together
        1. Methods of combining changes
          1. Merging branches
            1. No divergence – fast-forward and up-to-date cases
            2. Creating a merge commit
            3. Merge strategies and their options
            4. Reminder – merge drivers
            5. Reminder – signing merges and merging tags
          2. Copying and applying a changeset
            1. Cherry-pick – creating a copy of a changeset
            2. Revert – undoing an effect of a commit
            3. Applying a series of commits from patches
            4. Cherry-picking and reverting a merge
          3. Rebasing a branch
            1. Merge versus rebase
            2. Types of rebase
            3. Advanced rebasing techniques
        2. Resolving merge conflicts
          1. The three-way merge
          2. Examining failed merges
            1. Conflict markers in the worktree
            2. Three stages in the index
            3. Examining differences – the combined diff format
            4. How do we get there: git log --merge
          3. Avoiding merge conflicts
            1. Useful merge options
            2. Rerere – reuse recorded resolutions
          4. Dealing with merge conflicts
            1. Aborting a merge
            2. Selecting ours or theirs version
            3. Scriptable fixes – manual file remerging
            4. Using graphical merge tools
            5. Marking files as resolved and finalizing merges
            6. Resolving rebase conflicts
            7. git-imerge – incremental merge and rebase for git
        3. Summary
      8. 8. Keeping History Clean
        1. An introduction to Git internals
          1. Git objects
          2. The plumbing and porcelain Git commands
          3. Environment variables used by Git
            1. Environment variables affecting global behavior
            2. Environment variables affecting repository locations
            3. Environment variables affecting committing
        2. Rewriting history
          1. Amending the last commit
          2. An interactive rebase
            1. Reordering, removing, and fixing commits
            2. Squashing commits
            3. Splitting commits
            4. Testing each rebased commit
          3. External tools – patch management interfaces
          4. Scripted rewrite with the git filter-branch
            1. Running the filter-branch without filters
            2. Available filter types for filter-branch and their use
            3. Examples of using the git filter-branch
          5. External tools for large-scale history rewriting
            1. Removing files from the history with BFG Repo Cleaner
            2. Editing the repository history with reposurgeon
          6. The perils of rewriting published history
            1. The consequences of upstream rewrite
            2. Recovering from an upstream history rewrite
        3. Amending history without rewriting
          1. Reverting a commit
            1. Reverting a faulty merge
            2. Recovering from reverted merges
          2. Storing additional information with notes
            1. Adding notes to a commit
            2. How notes are stored
            3. Other categories and uses of notes
            4. Rewriting history and notes
            5. Publishing and retrieving notes
          3. Using the replacements mechanism
            1. The replacements mechanism
            2. Example – joining histories with git replace
            3. Historical note – grafts
            4. Publishing and retrieving replacements
        4. Summary
      9. 9. Managing Subprojects – Building a Living Framework
        1. Managing library and framework dependencies
          1. Managing dependencies outside Git
          2. Manually importing the code into your project
          3. A Git subtree for embedding the subproject code
            1. Creating a remote for a subproject
            2. Adding a subproject as a subtree
            3. Cloning and updating superprojects with subtrees
            4. Getting updates from subprojects with a subtree merge
            5. Showing changes between a subtree and its upstream
            6. Sending changes to the upstream of a subtree
          4. The Git submodules solution: repository inside repository
            1. Gitlinks, .git files, and the git submodule command
            2. Adding a subproject as a submodule
            3. Cloning superprojects with submodules
            4. Updating submodules after superproject changes
            5. Examining changes in a submodule
            6. Getting updates from the upstream of the submodule
            7. Sending submodule changes upstream
          5. Transforming a subfolder into a subtree or submodule
          6. Subtrees versus submodules
            1. Use cases for subtrees
            2. Use cases for submodules
            3. Third-party subproject management solutions
        2. Managing large Git repositories
          1. Handling repositories with a very long history
            1. Using shallow clones to get truncated history
            2. Cloning only a single branch
          2. Handling repositories with large binary files
            1. Splitting the binary asset folder into a separate submodule
            2. Storing large binary files outside the repository
        3. Summary
      10. 10. Customizing and Extending Git
        1. Git on the command line
          1. Git-aware command prompt
          2. Command-line completion for Git
          3. Autocorrection for Git commands
          4. Making the command line prettier
          5. Alternative command line
        2. Graphical interfaces
          1. Types of graphical tools
          2. Graphical diff and merge tools
          3. Graphical interface examples
        3. Configuring Git
          1. Command-line options and environment variables
          2. Git configuration files
            1. The syntax of Git configuration files
            2. Accessing the Git configuration
            3. Basic client-side configuration
            4. The rebase and merge setup, configuring pull
            5. Preserving undo information – the expiry of objects
            6. Formatting and whitespace
            7. Server-side configuration
          3. Per-file configuration with gitattributes
        4. Automating Git with hooks
          1. Installing a Git hook
          2. A template for repositories
          3. Client-side hooks
            1. Commit process hooks
            2. Hooks for applying patches from e-mails
            3. Other client-side hooks
          4. Server-side hooks
        5. Extending Git
          1. Command aliases for Git
          2. Adding new Git commands
          3. Credential helpers and remote helpers
        6. Summary
      11. 11. Git Administration
        1. Repository maintenance
        2. Data recovery and troubleshooting
          1. Recovering a lost commit
          2. Troubleshooting Git
        3. Git on the server
          1. Server-side hooks
            1. The pre-receive hook
            2. Push-to-update hook for pushing to nonbare repositories
            3. The update hook
            4. The post-receive hook
            5. The post-update hook (legacy mechanism)
          2. Using hooks to implement the Git-enforced policy
            1. Enforcing the policy with server-side hooks
            2. Early notices about policy violations with client-side hooks
          3. Signed pushes
          4. Serving Git repositories
            1. Local protocol
            2. SSH protocol
            3. Anonymous Git protocol
            4. Smart HTTP(S) protocol
            5. Dumb protocols
            6. Remote helpers
          5. Tools to manage Git repositories
          6. Tips and tricks for hosting repositories
            1. Reducing the size taken by repositories
            2. Speeding up smart protocols with pack bitmaps
            3. Solving the large nonresumable initial clone problem
        4. Augmenting development workflows
        5. Summary
      12. 12. Git Best Practices
        1. Starting a project
          1. Dividing work into repositories
          2. Selecting the collaboration workflow
          3. Choosing which files to keep under version control
        2. Working on a project
          1. Working on a topic branch
          2. Deciding what to base your work on
          3. Splitting changes into logically separate steps
          4. Writing a good commit message
          5. Preparing changes for submission
        3. Integrating changes
          1. Submitting and describing changes
          2. The art of the change review
          3. Responding to reviews and comments
        4. Other recommendations
          1. Don't panic, recovery is almost always possible
          2. Don't change the published history
          3. Numbering and tagging releases
          4. Automate what is possible
        5. Summary
    9. A. Bibliography
    10. Index