Book Image

Git Version Control Cookbook - Second Edition

By : Kenneth Geisshirt, Emanuele Zattin(EUR), Aske Olsson, Rasmus Voss
Book Image

Git Version Control Cookbook - Second Edition

By: Kenneth Geisshirt, Emanuele Zattin(EUR), Aske Olsson, Rasmus Voss

Overview of this book

Git is one of the most popular tools for versioning. With over 100 practical, self-contained tutorials, this updated version of the bestselling Git Version Control Cookbook examines the common pain points and best practices to help you solve problems related to versioning. Each recipe addresses a specific problem and offers a proven, best-practice solution with insights into how it works. You’ll get started by learning about the Git data model and how it stores files, along with gaining insights on how to commit changes to a database. Using simple commands, you’ll also understand how to navigate through the database. Once you have accustomed yourself to the basics, you’ll explore techniques to configure Git with the help of comprehensive examples and configuration targets. Further into the book, you’ll get up to speed with branches and recovery from mistakes. You’ll also discover the features of Git rebase and how to use regular Git to merge other branches. The later chapters will guide you in exploring Git notes and learning to utilize the update, list, and search commands. Toward the concluding chapters, you’ll focus on repository maintenance, patching, and offline sharing. By the end of this book, you’ll have grasped various tips and tricks, and have a practical understanding of best-practice solutions for common problems related to versioning.
Table of Contents (19 chapters)
Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
Index

Preface

Git is increasingly becoming the de facto standard for Source Control Management (SCM) in modern software development. 

Originally developed by Linus Torvalds as an 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 inspiration. 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, all the history is stored locally. You cansearch through the history, view the history, find the last commit on a certain branch, and more.
  • Using branches effectively with options and strategies to push, pull, and merge them.
  • Storing and extracting additional metadata in the Git repository.
  • Disaster recovery: local and global.

Git Version Control Cookbookgives you precise, step-by-step instructions for various common and uncommon Git operations. The book will make your daily work with Git easier by providingrecipes for common issues, useful tips and tricks, and in-depth clarifications of why andhow they work.

Who this book is for

This book targets developers, professional build/release managers, and DevOps practitioners who want a practical guide for the next level of Git. 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 the target audience. You need basic knowledge of common GNU/Linux tools and Shell/Bash scripting to get the most from this book.

What this book covers

Chapter 1,Navigating Git, shows how Git stores files and commits. Examples will visually showyou 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, 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,Rebasing 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 rebasing, such as cleaning up the history before publishing, and testing single commits.

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, shows 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 that will 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 relate to the maintenance and management of repositories, from forcing garbage collection, over-splitting, and joining repositories, to completely rewriting history.

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

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

Chapter 12Git Providers, Integrations, and Clients, introduces the largest Git-hosting site, GitHub. Moreover, the chapter will discuss how to integrate Jenkins for automated builds and tests.

To get the most out of 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 2.x 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.

 

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://www.packtpub.com/sites/default/files/downloads/GitVersionControlCookbookSecondEdition_ColorImages.pdf.

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "The most recent commit is the 3061dc6 Adds Java version of 'hello world'commit."

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

$ git checkout master && git reset --hard b14a939

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Select System info from the Administration panel."

Note

Warnings or important notes appear like this.

Note

Tips and tricks appear like this.

 

Sections

In this book, you will find several headings that appear frequently (Getting readyHow to do it..., How it works..., There's more..., and See also).

To give clear instructions on how to complete a recipe, use these sections as follows:

Getting ready

This section tells you what to expect in the recipe and describes how to set up any software or anypreliminary settings required for the recipe.

How to do it…

This section contains the steps required to follow the recipe.

How it works…

This section usually consists of a detailed explanation of what happened in the previous section.

There's more…

This section consists of additional information about the recipe in order to make you more knowledgeable about the recipe.

See also

This section provides helpful links to other useful information for the recipe.

 

Get in touch

Feedback from our readers is always welcome.

General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packtpub.com.