Free Sample
+ Collection

Git Version Control Cookbook

Aske Olsson, Rasmus Voss

90 hands-on recipes that will increase your productivity when using Git as a version control system
RRP $26.99
RRP $44.99
Print + eBook

Want this title & more?

$12.99 p/month

Subscribe to PacktLib

Enjoy full and instant access to over 2000 books and videos – you’ll find everything you need to stay ahead of the curve and make sure you can always get the job done.

Book Details

ISBN 139781782168454
Paperback340 pages

About This Book

  • Filled with practical recipes that will teach you how to use the most advanced features of the Git system
  • Improve your productivity by learning to work faster, more efficiently, and with more confidence
  • Discover tips and tricks that will show you when and how to use the advanced features of Git

Who This Book Is For

If you are a software developer or a build and release engineer who uses Git in your daily work and want to take your Git knowledge to the next level, then this book is for you. To understand and follow the recipes included in this book, basic knowledge of Git command-line code is mandatory.

Table of Contents

Chapter 1: Navigating Git
Git's objects
The three stages
Viewing the DAG
Extracting fixed issues
Getting a list of the changed files
Viewing history with Gitk
Finding commits in history
Searching through history code
Chapter 2: Configuration
Configuration targets
Querying the existing configuration
A .git directory template
A few configuration examples
Git aliases
The refspec exemplified
Chapter 3: Branching, Merging, and Options
Managing your local branches
Branches with remotes
Forcing a merge commit
Using git rerere to merge known conflicts
The difference between branches
Chapter 4: Rebase Regularly and Interactively, and Other Use Cases
Rebasing commits to another branch
Continuing a rebase with merge conflicts
Rebasing selective commits interactively
Squashing commits using an interactive rebase
Changing the author of commits using a rebase
Auto-squashing commits
Chapter 5: Storing Additional Information in Your Repository
Adding your first Git note
Separating notes by category
Retrieving notes from the remote repository
Pushing notes to a remote repository
Tagging commits in the repository
Chapter 6: Extracting Data from the Repository
Extracting the top contributor
Finding bottlenecks in the source tree
Grepping the commit messages
The contents of the releases
Chapter 7: Enhancing Your Daily Work with Git Hooks, Aliases, and Scripts
Using a branch description in the commit message
Creating a dynamic commit message template
Using external information in the commit message
Preventing the push of specific commits
Configuring and using Git aliases
Configuring and using Git scripts
Setting up and using a commit template
Chapter 8: Recovering from Mistakes
Undo – remove a commit completely
Undo – remove a commit and retain the changes to files
Undo – remove a commit and retain the changes in the staging area
Undo – working with a dirty area
Redo – recreate the latest commit with new changes
Revert – undo the changes introduced by a commit
Reverting a merge
Viewing past Git actions with git reflog
Finding lost changes with git fsck
Chapter 9: Repository Maintenance
Pruning remote branches
Running garbage collection manually
Turning off automatic garbage collection
Splitting a repository
Rewriting history – changing a single file
Back up your repositories as mirror repositories
A quick submodule how-to
Subtree merging
Submodule versus subtree merging
Chapter 10: Patching and Offline Sharing
Creating patches
Creating patches from branches
Applying patches
Sending patches
Creating Git bundles
Using a Git bundle
Creating archives from a tree
Chapter 11: Git Plumbing and Attributes
Displaying the repository information
Displaying the tree information
Displaying the file information
Writing a blob object to the database
Writing a tree object to the database
Writing a commit object to the database
Keyword expansion with attribute filters
Metadata diff of binary files
Storing binaries elsewhere
Checking the attributes of a file
Attributes to export an archive
Chapter 12: Tips and Tricks
Using git stash
Saving and applying stashes
Debugging with git bisect
Using the blame command
Color UI in the prompt
Bash prompt with status information
More aliases
Interactive add
Interactive add with Git GUI
Ignoring files
Showing and cleaning ignored files

What You Will Learn

  • Understand the Git data model and how you can navigate the database with simple commands
  • Learn how you can recover lost commits/files
  • Discover how you can force rebase on some branches and use regular Git merge on other branches
  • Extract metadata from a Git repository
  • Familiarize yourself with Git notes
  • Discover how you can work offline with Git
  • Debug with Git and use various techniques to find the faulty commit

In Detail

Starting with the Git data model, you will learn how Git stores files and how it looks at commits. You will then learn how you can recover from mistakes; from committing on the wrong branch to recovering lost commits/files. Next, you will discover how you can force rebase on some branches and use regular Git merge on other branches. You will also learn how to extract information from the repository.

As you progress through this book, you will learn how you can automate the usual Git processes by utilizing the hook system built into Git. The book also covers advanced repository management, including different options to rewrite the history of a Git repository. Finally, you will 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.


Read More