Mastering Git - Jakub Narębski - E-Book

Mastering Git E-Book

Jakub Narebski

0,0
29,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.
Mehr erfahren.
Beschreibung

Developers often feel overwhelmed by complex version control issues, especially when managing large repositories. This updated second edition of our Git guide empowers you to tackle these challenges head-on and emerge as a Git pro.
The book gets you up to speed with the latest Git version, its features, and advanced branching techniques, helping you master complex development scenarios. A new chapter on tackling challenges while managing large repositories has been added, providing invaluable strategies for efficient version control with Git. The book goes beyond the basics to take you through Git’s architecture, behavior, and best practices in depth. The chapters help you develop a clear understanding of customizing workflows, creating unique solutions, and tackling any version control hurdle. As you advance, you’ll explore a wide range of functionalities, from examining project history to collaborating seamlessly with teammates. Detailed descriptions guide you through managing your work, collaborating with others, administering Git, and navigating project history.
By the end of this book, you’ll have become a Git pro and be confident enough to handle advanced branching, manage large repositories, customize workflows, collaborate effectively, and troubleshoot any version control issues.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 777

Veröffentlichungsjahr: 2024

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Mastering Git

Attain expert-level proficiency with Git by mastering distributed version control features

Jakub Narębski

Mastering Git

Copyright © 2024 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Group Product Manager: Preet Ahuja

Publishing Product Manager: Vidhi Vashisth

Book Project Manager: Ashwini Gowda

Senior Editor: Roshan Ravi Kumar

Technical Editor: Irfa Ansari

Copy Editor: Safis Editing

Proofreader: Roshan Ravi Kumar

Indexer: Rekha Nair

Production Designer: Alishon Mendonca

Senior Developer Relations Marketing Executive: Rohan Dobhal

First published: April 2016

Second edition: August 2024

Production reference: 1290724

Published by Packt Publishing Ltd.

Grosvenor House

11 St Paul’s Square

Birmingham

B3 1RB, UK

ISBN 978-1-83508-607-0

www.packtpub.com

Contributors

About the author

Jakub Narębski followed Git development from the very beginning of its creation. He created, announced, and analyzed the annual Git User’s Surveys from 2007 till 2012 – all except the first one (you can find his analysis of those surveys on the Git wiki). He shares his expertise in the technology on the StackOverflow question-and-answer site. He is one of the editors of Git Rev News (https://git.github.io/rev_news/), which is a monthly digest of all things Git.

He is an assistant professor in the Faculty of Mathematics and Computer Science at the Nicolaus Copernicus University in Toruń, Poland. He uses Git as his version control system of choice both for personal and professional work and teaches it to computer science students as a part of their coursework.

Jakub Narębski was one of the proofreaders of the Version Control by Example book by Eric Sink, and was the reason why it has a chapter on Git.

About the reviewer

Samuel Ng has worked as a data engineer for 3 years. He first started as a systems engineer working on military projects in Singapore before moving into the data sphere. His career has seen him gain experience in multiple industries including semiconductors, military, blockchain and now manufacturing, across Singapore, the Philippines, and South Korea. In his free time, he likes to read up on advancements in AI and his current interest is in GenAI.

I want to thank the author of this book, Jakub, for his effort in creating excellent content for Git readers. Also to the team at Packt, for the opportunity to be part of this amazing project. I hope that you, the reader, will find this content useful in your Git journey, and excel in any tech project that you undertake.

Table of Contents

Preface

Part 1 - Exploring Project History and Managing Your Own Work

1

Git Basics in Practice

Technical requirements

A brief introduction to version control and Git

Git by example

Setup and initialization

Collaborative development

Branching and merging

Summary

Questions

Answers

Further reading

2

Developing with Git

Creating a new commit

How a new commit extends a project’s history

The index — a staging area for commits

Examining the changes to be committed

Selective commit

Amending a commit

Working with branches and tags

Creating a new branch

Creating orphan branches

Selecting and switching to a branch

Listing branches and tags

Rewinding or resetting a branch

Deleting a branch

Changing the branch name

Summary

Questions

Answers

Further reading

3

Managing Your Worktrees

Ignoring files

Marking files as intentionally untracked (ignored)

Which types of files should be ignored?

Listing ignored files

Trick – ignoring changes in tracked files

File attributes

Identifying binary files and end-of-line conversions

Diff and merge configuration

Transforming files (content filtering)

Keyword expansion and substitution

Other built-in attributes

Defining attribute macros

Fixing mistakes with the reset command

Rewinding the branch head, softly

Resetting the branch head and the index

Discarding changes and rewinding the branch

Safer reset – keeping your changes

Stashing away your changes

Using git stash

Stash and the staging area

Stash internals

Managing worktrees and the staging area

Examining files and directories

Searching file contents

Un-tracking, un-staging, and un-modifying files

Resetting a file to the old version

Cleaning the working area

Multiple working directories

Summary

Questions

Answers

Further reading

4

Exploring Project History

DAGs

Whole-tree commits

Branches and tags

Branch points

Merge commits

Single revision selection

HEAD – the implicit revision

Branch and tag references

The --branches, --tags, and similar options

SHA-1 and the shortened SHA-1 identifier

Ancestry references

Reverse ancestry references – git-describe output

Reflogging shortnames

Upstreaming remote-tracking branches

Selecting revisions via a commit message

Selecting the revision range

Single revision as a revision range

Double-dot notation

Creating the range by including and excluding revisions

The revision range for a single revision

Triple-dot notation

Summary

Questions

Answers

Further reading

5

Searching Through the Repository

Searching the history

Limiting the number of revisions

Matching revision metadata

Searching changes in revisions

Selecting types of changes

History of a file

Path limiting

History simplification

Blame — the line-wise history of a file

Finding bugs with git bisect

Starting the git bisect process

Finding the buggy commit

Automating testing during the git bisect process

Selecting and formatting the git log output

Predefined and user-defined output formats

Including, formatting, and summing up changes

Summarizing contributions

Mapping authors

Viewing a revision and a file at revision

Summary

Questions

Answers

Further reading

Part 2 - Working with Other Developers

6

Collaborative Development with Git

Collaborative workflows

Bare repositories

Interacting with other repositories

The centralized workflow

The peer-to-peer or forking workflow

The maintainer or integration manager workflow

The hierarchical or dictator-and-lieutenants workflow

Managing remote repositories

The “origin” remote

Listing and examining remotes

Adding a new remote

Updating information about remotes

Support for triangular workflows

Chain of trust

Content-addressed storage

Lightweight, annotated, and signed tags

Signed commits

Merging signed tags (merge tags)

Summary

Questions

Answers

Further reading

7

Publishing Your Changes

Transport protocols and remote helpers

Local transport

Smart transports

Legacy (dumb) transports

Offline transport with bundles

Remote transport helpers

Credentials/password management

Publishing your changes upstream

Pushing to a public repository

Generating a pull request

Exchanging patches

Summary

Questions

Answers

Further reading

8

Advanced Branching Techniques

The purpose of branching

Isolation versus integration

The path to production release

Long-running and short-lived branches

Visibility of branches

Alternatives to branching

Visibility without integration

Branching patterns

Integration patterns

Release engineering

Other branching patterns involving long-lived branches

Other types of short-lived branches

Branching workflows and release engineering

The release and trunk branches workflow

The graduation branches workflow

The topic branches workflow

git-flow – a successful Git branching model

Ship/Show/Ask – a modern branching strategy

Fixing a security issue

Interacting with branches in remote repositories

Upstream and downstream

Remote-tracking branches and refspec

Fetching and pulling versus pushing

Fetching and pushing branches and tags

Push modes and their use

Summary

Questions

Answers

Further reading

9

Merging Changes Together

Methods of combining changes

Merging branches

Copying and applying a changeset

Rebasing a branch

Squash merge

Resolving merge conflicts

The three-way merge

Examining failed merges

Avoiding merge conflicts

Dealing with merge conflicts

Summary

Questions

Answers

Further reading

10

Keeping History Clean

An introduction to Git internals

Git objects

Plumbing and porcelain Git commands

Rewriting history

Amending the last commit

The interactive rebase

External tools – patching management interfaces

Rewriting project history with Git filter-repo

External tools for large-scale history rewriting

The perils of rewriting published history

Amending history without rewriting

Reverting a commit

Storing additional information with notes

Using git replace

Summary

Questions

Answers

Further reading

Part 3 - Managing, Configuring, and Extending Git

11

Managing Subprojects

Building a living framework

Managing dependencies outside of Git

Manually importing the code into your project

A Git subtree solution for embedding the subproject code

Creating a remote for a subproject

Adding a subproject as a subtree

Cloning and updating superprojects with subtrees

Getting updates from subprojects with a subtree merge

Showing changes between a subtree and its upstream

Sending changes to the upstream of a subtree

The Git submodules solution – a repository inside a repository

Gitlinks, .git files, and the git submodule command

Adding a subproject as a submodule

Cloning superprojects with submodules

Updating submodules after superproject changes

Examining changes in a submodule

Getting updates from the upstream of the submodule

Sending submodule changes upstream

Transforming a subfolder into a subtree or submodule

Subtrees versus submodules

Use cases for subtrees

Use cases for monorepo

Use cases for submodules

Third-party subproject management solutions

Summary

Questions

Answers

Further reading

12

Managing Large Repositories

Scalar – Git at scale for everyone

Handling repositories with a very long history

Using shallow clones to get truncated history

Cloning only a single branch

Making operations faster in repositories with a long history

Handling repositories with large binary files

Splitting the binary asset folder into a separate submodule

Storing large binary files outside the repository

Handling repositories with a large number of files

Limiting the number of working directory files with sparse checkout

Reducing the local repository size with sparse clone

Faster checking for file changes with filesystem monitor

Summary

Questions

Answers

Further reading

13

Customizing and Extending Git

Git on the command line

Git-aware command prompt

Command-line completion for Git

Autocorrection for Git commands

Making the command line prettier

Alternative command line

Graphical interfaces

Types of graphical tools

Graphical diff and merge tools

Graphical interface examples

Configuring Git

Command-line options and environment variables

Git configuration files

Per-file configuration with gitattributes

Automating Git with hooks

Installing a Git hook

A template for repositories

Client-side hooks

Server-side hooks

Extending Git

Command aliases for Git

Adding new Git commands

Credential helpers and remote helpers

Summary

Questions

Answers

Further reading

14

Git Administration

Repository maintenance

Automatic housekeeping with git-gc

Periodic maintenance with git-maintenance

Data recovery and troubleshooting

Recovering a lost commit

Troubleshooting Git

Git on the server

Server-side hooks

Using hooks to implement Git-enforced policy

Signed pushes

Serving Git repositories

Tools to manage Git repositories

Tips and tricks to host repositories

Augmenting development workflows

Defining development workflows in the repository

GitOps – using Git for operational procedures

Summary

Questions

Answers

Further reading

15

Git Best Practices

Starting a project

Dividing work into repositories

Selecting the collaboration workflow

Choosing which files to keep under version control

Working on a project

Working on a topic branch

Deciding what to base your work on

Splitting changes into logically separate steps

Writing a good commit message

Preparing changes for submission

Integrating changes

Submitting and describing changes

The art of the change review

Responding to reviews and comments

Other recommendations

Don’t panic, recovery is almost always possible

Don’t change the published history

Numbering and tagging releases

Automate where possible

Summary

Further reading

Index

Other Books You May Enjoy

Part 1 - Exploring Project History and Managing Your Own Work

In this part, you will start by understanding the basics of using Git in a simple example. You will then learn how to use it to answer questions about the project and its history. You will also learn how to examine the state of your worktree, manage changes, and create a good commit.

This part has the following chapters:

Chapter 1, Git Basics in PracticeChapter 2, Developing with GitChapter 3, Managing Your WorktreesChapter 4, Exploring Project HistoryChapter 5, Searching Through the Repository