Feineigle.com - Git Essentials

Home · Book Reports · 2018 · Git Essentials

Published: August 20, 2018 (5 years 7 months ago.)
Tags:  Git · Programming



The book in...
One sentence:
A detailed, hands-on look at using, in a long-form tutorial format, ranging from total ignorant to semi-advanced, and understanding Git.

Five sentences:
After a basic how-to-install introduction you are thrown into the tutorial straight away, learning the basic commands, like init, add, and commit, to get you up and running. After the absolute basics are covered, the book moves toward a more, but not totally complete, understanding of working with local repositories. This is extended to working remotely, with more niche commands, and finally with an overview of the configuration system within Git. Now that you have an understanding and a tutorial under your belt, the most important part is covered; best practices for commits and the various workflows your team can adopt to simplify development. Finally there is a small pair of chapters on migrating from Subversion and a list of resources that lead to other articles, books, tutorials, cheatsheets, and the like, mostly online.

designates my notes. / designates important.


Thoughts

From the introduction I thought this was going to be heavier; it talks about gaining a deep understanding of Git and that the book is more than a tutorial. I disagree. While there is enough to give you a very good understanding, none of it is difficult and I personally made my way though the book in a matter of a few days even following along by executing the tutorial.

That said, this is a great book to learn Git with. Everything is well explained and flows logically from topic to topic. It occasionally gets down in the grass and explains the underlying principles, but only occasionally. Most of the time it is straight forward, even to the point of repetitive. This occasional repetition is perfectly acceptable since you are, presumably, learning something new.

It starts off as you’d expect, with the install process for the big three operating systems. The main tutorial is presented from Windows, but through a bash emulator. It worked as described, flawlessly, on my Linux system.

Once installed, you set up a repo and then head to chapter 2.

In chapter 2 you set up another repo (practice practice practice) that will be used throughout most of the rest of the book. The concept used is a simple shopping list full of various fruits for the fruit salad you are planning to make.

There are many digressions in chapter 2 to explain some of the underlying concepts and functionality of Git. The first is the distinguishing of porcelain and plumbing commands. This analogy, thought up by Torvalds, refers to the clean, barely changing commands most users will be familiar with; the porcelain. Other, the plumbing, commands change more frequently but can be more powerful. While some plumbing commands are covered, you don’t really need to know them.

Next objects are discussed. Git has four objects: commits, trees, blobs, and annotated tags. Commits are, well commits! Trees you can think of as folders, blobs as files. Annotated tags are just that, tags.

When making commits, Git takes snapshots, not deltas, but if something is unchanged it is recycles. This means that multiple trees can point to the same (unchanged) blob.

Naturally branches come up next. These, being so important, are covered to a great extent. Navigating branches, with shortcuts like tilde and caret, and resetting branches are some of the more introductory topics.

Somewhat more advanced are the reglogs, which track (for 90 days by default) everything you do, are covered. These allow you to find hashes for old commits.

Tags, another way to mark your way path in your project, are mentioned. There is no hard and fast rules for tags; teams can use them as they see fit. There isn’t much to say, a tag is a tag!

Next staging and unstaging, the nuts and bolts of getting ready to make customized and meaningful commits is covered.

Finally we get to merging, which is presented in such a way that makes it very approachable. Those without and understanding of merging may think it is voodoo magic, but this book shows you exactly how it works and how to easily navigate the dreaded merge conflict. Alternatively many tips are given so that you might avoid a conflict in the first place.

In the same vein, cherry-picking, which is somewhat more complicated, is covered. This is essentially taking bits and pieces from various commits on multiple branches and merging them into master (or wherever).

Basically this (long) chapter contains everything you need to know to work (locally) with Git.

Chapter three follows up with how to work, surprise, remotely! It follows the same path: setting up, making changes with pushes and pulls, and the GitHub specific forking and pull request.

Chapter four is more a tips and tricks chapter. Aliases, custom commands, can be created for Git in much the same way you can create aliases in bash.

A, somewhat tangential, tip lets you know that, while Git feels like a backup, you should not treat it as such. Always follow proper backup procedures, even when dealing with remote repositories. Although, the distributed nature of a shared project will provide you with a bit of extra insurance.

There are some tips on creating bare repositories, for example if you’ve been working locally but now want to share your project, and bundling to help share your project with non Git users.

Chapter five, after the initial technical understanding is absorbed, is probably the most important part of the book. It sets out to detail some best practices for things like committing and commit messages. Again, there are no hard and fast rules, and your team may have a policy in place when you arrive on a new project, but these are worth taking a good hard look at.

First, there should be only one change per commit. This makes it much simpler to see the log as a changelog one feature at a time, as well as increases the simplicity in cherry-picking.

To simplify the process of making commits, since you will likely do more than one change per day and often be pulled away into meetings and such, you can start, before writing or changing a single line of code, by scribbling down a list of all the tasks you need to accomplish. Next you can break them down into atomic bits. Keep breaking them down until it doesn’t feel natural to split them into smaller parts. This will be subjective. Then, write a single sentence that describes each of the parts. Bingo, you’ve got your commit messages pre-written. Now, just follow you plan. If you get pulled into a meeting, simply pick up where you left off later.

Chapter six, which I admittedly skim quickly, offers instruction for migrating from Subversion and a comparison of Git versus Subversion.

The last chapter, seven, includes a selection of various resources. There are a large number of GUI options, mostly for Windows, a personal web GUI to manage your self-hosted remote, several websites that offer tutorials, advice, or visualization, as well as a few links to cheatsheets.

Further Reading


Exceptional Excerpts

“only make one change per commit."


Table of Contents


· 01: Getting Started with Git

· 02: Git Fundamentals - Working Locally

page 67:
page 75:
page 98:
[23] ~/grocery (master)
$ git checkout -
Switched to branch 'berries'
page 100:
page 116:
page 120:
The working tree (or working directory)
The staging area (or index, or cache)
The HEAD commit (or the last commit or tip commit on the current branch)
page 122:
page 124:
page 126:

· 03: Git Fundamentals - Working Remotely

page 166:
page 168:

· 04: Git Fundamentals - Niche Concepts, Configurations, and Commands

page 207:
page 218:
[1] ~/grocery (master)
$ git config --global alias.unstage 'reset HEAD --'
[2] ~/grocery (master)
$ git unstage myFile.txt
[3] ~/grocery (master)
$ git reset HEAD -- myFile.txt
page 234:
page 235:
$ git clone --bare my_project my_project.git

· 05: Obtaining the Most - Good Commits and Workflows

page 243:

page 245:
page 246:
page 261:
page 268:

· 06: Migrating to Git

· 07: Git Resources

page 317:
page 320:
Git pretty: http://justinhileman.info/article/git-pretty/
Hylke Bons Git cheat sheet: https://github.com/hbons/git-cheat-sheet