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

Preventing the push of specific commits


The pre-push hooks are triggered whenever you use the push command and the script execution happens before the push. So, we can prevent a push if we find a reason to reject it.

One reason could be that you have a commit with the nopush text in the commit message.

Getting ready

To use the Git pre-push, we need to have a remote repository. We will be cloning jgit again, as follows:

$ git clone https://git.eclipse.org/r/jgit/jgit chapter7.1
Cloning into 'chapter7.1'...
  remote: Counting objects: 2429, done
  remote: Finding sources: 100% (534/534)
  remote: Total 45639 (delta 145), reused 45578 (delta 145)
  Receiving objects: 100% (45639/45639), 10.44 MiB | 2.07 MiB/s, done.
  Resolving deltas: 100% (24528/24528), done.
  Checking connectivity... done.
  Checking out files: 100% (1576/1576), done.

How to do it...

We want to be able to push to a remote branch but, unfortunately, Git will try to authenticate through HTTPS for the jgit repository before the...