Git Version Control Cookbook

Book description

A series of practical recipes to simplify the Git learning experience and increase your productivity when using Git version control

Key Features

  • Explore practical recipes to use Git's most advanced features
  • Learn how Git references its objects and how history is recorded
  • Use reflog and git fsck to recover lost information

Book Description

Git is one of the most popular tools for versioning. Git Version Control Cookbook builds on the success of the previous edition and provides you with an up-to-date guide to solving problems related to versioning.

You'll start by learning about the Git data model and how it stores files and looks at commits. By using simple commands, you'll learn how to navigate through the database. Once you have accustomed yourself to the basics, you'll explore techniques to configure Git with comprehensive examples and configuration targets. You'll gain insights into improving your understanding of branches and recovery from mistakes — right from committing to a wrong branch to recovering lost commits or files. You'll then move on to discovering the features that Git rebase has to offer and use regular Git merge on other branches. You'll explore Git notes and learn how to utilize the update, list, and search commands. In addition to this, you'll learn how to extract metadata from repositories and automate your daily tasks using Git hooks. You'll then study in detail repository maintenance, patching, and offline sharing. By the end of the book, you'll have grasped various tips and tricks for everyday usage, while increasing your knowledge of Git providers, integrations, and clients.

What you will learn

  • Understand the Git data model and use commands to navigate the database
  • Find out how you can recover lost commits or files
  • Force a rebase on some branches and use regular Git to merge on the rest
  • Master the techniques required to extract metadata from repositories
  • Explore Git notes and learn about the various features that it offers
  • See how to decode different subcommands

Who this book is for

The Git Version Control Cookbook is for you if you are a developer or Build Release manager looking for a full-fledged practical guide that will take your Git knowledge to the next level. Basic knowledge of GNU tools and shell or bash scripting is needed.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Git Version Control Cookbook Second Edition
  3. Packt Upsell
    1. Why subscribe?
    2. PacktPub.com
  4. Contributors
    1. About the authors
    2. About the reviewer
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the color images
      2. Conventions used
    4. Sections
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    5. Get in touch
      1. Reviews
  6. 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 object
        5. The tag object
      3. How it works...
      4. There's more...
    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...
    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 the history with gitk
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. Finding commits in the history
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    9. Searching through the history code
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  7. Configuration
    1. Introduction
    2. Configuration targets
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Querying the existing configuration
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Templates
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. A .git directory template
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. 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...
    7. Git aliases
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. The refspec exemplified
      1. Getting ready
      2. How to do it...
      3. How it works...
  8. 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 reuse recorded resolution (rerere) to merge Git conflicts
      1. How to do it...
      2. There's more...
    6. Compute the difference between branches
      1. Getting ready
      2. How to do it...
    7. Orphan branches
      1. Getting ready
      2. How to do it...
      3. There's more...
  9. Rebasing 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 selected 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. Autosquashing commits
      1. Getting ready
      2. How to do it...
      3. There's more...
  10. 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 Git 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...
  11. 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...
    6. Finding what has been achieved in the repository in the last period
      1. How to do it...
      2. How it works...
      3. There's more...
  12. Enhancing Your Daily Work with Git Hooks, Aliases, and Scripts
    1. Introduction
    2. Using a branch description in a 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 a 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...
  13. 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 changes to files
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Undo – Remove a commit and retain 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...
    6. Redo – Recreate the latest commit with new changes
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's 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's 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...
  14. 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. Creating a backup of your repositories as mirror repositories
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. A quick "how-to" submodule
      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
  15. 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...
  16. 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. Coloring the 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...
  17. Git Providers, Integrations, and Clients
    1. Introduction
    2. Setting up an organization at GitHub
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Creating a repository at GitHub
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Adding templates for issues and pull requests
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Creating a GitHub API key
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    6. Using GitHub to authenticate at Jenkins
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    7. Triggering Jenkins builds
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    8. Using Jenkinsfiles
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  18. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Git Version Control Cookbook
  • Author(s): Kenneth Geisshirt, Emanuele Zattin, Rasmus Voss, Aske Olsson
  • Release date: July 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781789137545