Book Image

Git Version Control Cookbook

Book Image

Git Version Control Cookbook

Overview of this book

Table of Contents (19 chapters)
Git Version Control Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Git is the clear leader in the new paradigm of distributed version control systems. Originally developed by Linus Torvalds as a source control management (SCM) system for the Linux kernel to replace the proprietary SCM BitKeeper, Git has since conquered most of the open source world and is also used by lots of organizations for their private/proprietary projects.

This book is designed to give you practical recipes for everyday Git usage. The recipes can be used directly or as an inspiration for you. The book will cover the Git data model through practical recipes and in-depth explanations so you get a deeper understanding of the internal workings of Git. This book will show you the following topics:

  • Working with the history. With Git, you have all the history stored locally. Use it to search through the history, view the history, find the last commit touching a particular line, and so on.

  • Using branches effectively with options and strategies to push, pull, and merge.

  • Storing and extracting additional metadata in the Git repository.

  • Disaster recovery: local and global.

Git Version Control Cookbook gives you precise step-by-step instructions to various common and uncommon Git operations. The book can help ease your daily work with Git by providing recipes for common issues, useful tips and tricks, and in-depth clarifications of why and how they work.

What this book covers

Chapter 1, Navigating Git, shows how Git stores files and commits. Examples will visually show you the data model and how to navigate the history and database with simple commands.

Chapter 2, Configuration, shows how a lot can be configured in Git and how configuration targets are set, the different configuration levels, and some useful targets.

Chapter 3, Branching, Merging, and Options, will give you a deeper understanding of branching and the options for easy push/pull targets. It also shows you the different merge strategies and some tips on how to record merge resolutions.

Chapter 4, Rebase Regularly and Interactively, and Other Use Cases, shows you how rebasing can be used instead of merging along with a lot of other use cases of rebase: cleaning up the history before publishing, testing single commits, and so on.

Chapter 5, Storing Additional Information in Your Repository, takes you on a tour of Git notes. It will show you how to tie additional information to a commit, and how to use and see this information again.

Chapter 6, Extracting Data from the Repository, will show you how to extract statistics and other metadata from the repository.

Chapter 7, Enhancing Your Daily Work with Git Hooks, Aliases, and Scripts, contains a collection of recipes to help you automate much of the tedious daily work.

Chapter 8, Recovering from Mistakes, walks you through several recovery scenarios, from local undo, to where-is-my-old-commit, to global recovery scenarios.

Chapter 9, Repository Maintenance, is a collection of recipes that concern the maintenance and management of repositories, from forcing garbage collection, over-splitting, and joining repositories to complete history rewriting.

Chapter 10, Patching and Offline Sharing, shows you how to work offline with Git and share the work by means other than pushing and pulling.

Chapter 11, Git Plumbing and Attributes, has a collection of recipes that show you how to utilize the filter feature of Git and a small collection of recipes that cover some of the useful but not widely known plumbing commands.

Chapter 12, Tips and Tricks, is a collection of recipes that covers various topics, from simple tips to displaying the current branch in your prompt to advanced Git tools, such as bisect and stash.

What you need for this book

To follow and recreate the recipes from this book, you will need a computer preferably running a *NIX operating system. You will need Git installed, preferably Git Version 1.8 or later.

If you are a Windows user, we recommend the Git Extensions package, which ships both a graphical and textual (bash) Git interface. The latter is required for the recipes in this book.

Who this book is for

This book targets both developers, as well as professional build/release managers who want a practical guide for the next level of Git. There is something for everyone. Starting with the Git data model and advancing through branching to metadata and hooks, all through an easy-to-read recipe structure, the transition from simple everyday use cases to advanced repository handling is smooth. The book can be easily read and understood by readers from all categories. The book requires basic knowledge of common GNU/Linux tools and shell/bash scripting.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input are shown as follows: "Again, we will use the JGit repository with the master branch pointing to b14a939."

Any command-line input or output is written as follows:

$ git log -G"isOutdated" --oneline 

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "We can just write the commit message in the field in the bottom of the screen and hit Commit."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title through the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

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 files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website, or added to any list of existing errata, under the Errata section of that title.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.