How to use this Book: Intro
Note
In this section, we answer the burning question: “So why DID they put that in a Git book?”
Who is this book for?
If you can answer “yes” to both of these:
Do you want to learn about the world’s most popular version control system?
Do you prefer stimulating dinner-party conversation to dry, dull, academic lectures?
This book is for you.
Who should probably back away from this book?
If you can answer “yes” to any of these:
Are you completely new to computers?
(You don’t need to be advanced, but you should understand folders and files, how to open applications, and how to use a simple text editor.)
Are you a version control system maestro looking for a reference book?
Are you afraid to try something new? Would you rather have a root canal than mix stripes with plaid? Do you believe that a technical book can’t be serious if it uses mouth-watering menu items to explain branching?
This book is not for you.
Note
[Note from marketing: This book is for anyone with a credit card.]
We know what you’re thinking
“How can this be a serious book on Git?”
“What’s with all the graphics?”
“Can I actually learn it this way?”
We know what your brain is thinking
Your brain craves novelty. It’s always searching, scanning, waiting for something unusual. It was built that way, and it helps you stay alive.
So what does your brain do with all the routine, ordinary, normal things you encounter? Everything it can to stop them from interfering with the brain’s real job—recording things that matter. It doesn’t bother saving the boring things; they never make it past the “this is obviously not important” filter.
How does your brain know what’s important? Suppose you’re out for a day hike and a tiger jumps in front of you. What happens inside your head and body?
Neurons fire. Emotions crank up. Chemicals surge.
And that’s how your brain knows...
This must be important! Don’t forget it!
But imagine you’re at home or in a library. It’s a safe, warm, tiger-free zone. You’re studying. Getting ready for an exam. Or trying to learn some tough technical topic your boss thinks will take a week, 10 days at the most.
Just one problem. Your brain’s trying to do you a big favor. It’s trying to make sure that this obviously unimportant content doesn’t clutter up scarce resources. Resources that are better spent storing the really big things. Like tigers. Like the danger of fire. Like how you should never have posted those “party” photos on your Facebook page. And there’s no simple way to tell your brain, “Hey brain, thank you very much, but no matter how dull this book is, and how little I’m registering on the emotional Richter scale right now, I really do want you to keep this stuff around.”
Metacognition: thinking about thinking
If you really want to learn, and you want to learn more quickly and more deeply, pay attention to how you pay attention. Think about how you think. Learn how you learn.
Most of us did not take courses on metacognition or learning theory when we were growing up. We were expected to learn, but rarely taught to learn.
But we assume that if you’re holding this book, you really want to learn how to use Git. And you probably don’t want to spend a lot of time on it. If you want to use what you read in this book, you need to remember what you read. And for that, you’ve got to understand it. To get the most from this book, or any book or learning experience, take responsibility for your brain. Your brain on this content.
The trick is to get your brain to see the new material you’re learning as Really Important. Crucial to your well-being. As important as a tiger. Otherwise, you’re in for a constant battle, with your brain doing its best to keep the new content from sticking.
So just how DO you get your brain to treat Git like it’s a hungry tiger?
There’s the slow, tedious way, or the faster, more effective way. The slow way is about sheer repetition. You obviously know that you are able to learn and remember even the dullest of topics if you keep pounding the same thing into your brain. With enough repetition, your brain says, “This doesn’t feel important, but they keep looking at the same thing over and over and over, so I suppose it must be.”
The faster way is to do anything that increases brain activity, especially different types of brain activity. The things on the previous page are a big part of the solution, and they’re all things that have been proven to help your brain work in your favor. For example, studies show that putting words within the pictures they describe (as opposed to somewhere else on the page, like a caption or in the body text) causes your brain to try to make sense of how the words and picture relate, and this causes more neurons to fire. More neurons firing = more chances for your brain to get that this is something worth paying attention to, and possibly recording.
A conversational style helps because people tend to pay more attention when they perceive that they’re in a conversation, since they’re expected to follow along and hold up their end. The amazing thing is, your brain doesn’t necessarily care that the “conversation” is between you and a book! On the other hand, if the writing style is formal and dry, your brain perceives it the same way you experience being lectured to while sitting in a roomful of passive attendees. No need to stay awake.
But pictures and conversational style are just the beginning…
Here’s what WE did
We used visuals, because your brain is tuned for visuals, not text. As far as your brain’s concerned, a visual really is worth a thousand words. And when text and visuals work together, we embedded the text in the visuals because your brain works more effectively when the text is within the thing the text refers to, as opposed to in a caption or buried in a paragraph somewhere.
We used redundancy, saying the same thing in different ways and with different media types, and multiple senses, to increase the chance that the content gets coded into more than one area of your brain.
We used concepts and visuals in unexpected ways because your brain is tuned for novelty, and we used visuals and ideas with at least some emotional content, because your brain is tuned to pay attention to the biochemistry of emotions. That which causes you to feel something is more likely to be remembered, even if that feeling is nothing more than a little humor, surprise, or interest.
We used a personalized, conversational style, because your brain is tuned to pay more attention when it believes you’re in a conversation than if it thinks you’re passively listening to a presentation. Your brain does this even when you’re reading.
We included dozens of activities, because your brain is tuned to learn and remember more when you do things than when you read about things. And we made the exercises challenging yet doable, because that’s what most people prefer.
We used multiple learning styles, because you might prefer step-by-step procedures, while someone else wants to understand the big picture first, and someone else just wants to see an example. But regardless of your own learning preference, everyone benefits from seeing the same content represented in multiple ways.
We include content for both sides of your brain, because the more of your brain you engage, the more likely you are to learn and remember, and the longer you can stay focused. Since working one side of the brain often means giving the other side a chance to rest, you can be more productive at learning for a longer period of time.
And we included stories and exercises that present more than one point of view, because your brain is tuned to learn more deeply when it’s forced to make evaluations and judgments.
We included challenges, with exercises, and we asked questions that don’t always have a straight answer, because your brain is tuned to learn and remember when it has to work at something. Think about it—you can’t get your body in shape just by watching people at the gym. But we did our best to make sure that when you’re working hard, it’s on the right things. That you’re not spending one extra dendrite processing a hard-to-understand example, or parsing difficult, jargon-laden, or overly terse text.
We used people. In stories, examples, visuals, etc., because, well, because you’re a person. And your brain pays more attention to people than it does to things.
Here’s what YOU can do to bend your brain into submission
So, we did our part. The rest is up to you. These tips are a starting point; listen to your brain and figure out what works for you and what doesn’t. Try new things.
Note
Cut this out and stick it on your refrigerator.
Slow down. The more you understand, the less you have to memorize.
Don’t just read. Stop and think. When the book asks you a question, don’t just skip to the answer. Imagine that someone really is asking the question. The more deeply you force your brain to think, the better chance you have of learning and remembering.
Do the exercises. Write your own notes.
We put them in, but if we did them for you, that would be like having someone else do your workouts for you. And don’t just look at the exercises. Use a pencil. There’s plenty of evidence that physical activity while learning can increase the learning.
Read the “There Are No Dumb Questions.”
That means all of them. They’re not optional sidebars, they’re part of the core content! Don’t skip them.
Make this the last thing you read before bed. Or at least the last challenging thing.
Part of the learning (especially the transfer to long-term memory) happens after you put the book down. Your brain needs time on its own, to do more processing. If you put in something new during that processing time, some of what you just learned will be lost.
Talk about it. Out loud.
Speaking activates a different part of the brain. If you’re trying to understand something, or increase your chance of remembering it later, say it out loud. Better still, try to explain it out loud to someone else. You’ll learn more quickly, and you might uncover ideas you hadn’t known were there when you were reading about it.
Drink water. Lots of it.
Your brain works best in a nice bath of fluid. Dehydration (which can happen before you ever feel thirsty) decreases cognitive function.
Listen to your brain.
Pay attention to whether your brain is getting overloaded. If you find yourself starting to skim the surface or forget what you just read, it’s time for a break. Once you go past a certain point, you won’t learn faster by trying to shove more in, and you might even hurt the process.
Feel something.
Your brain needs to know that this matters. Get involved with the stories. Make up your own captions for the photos. Groaning over a bad joke is still better than feeling nothing at all.
Use it everyday!
There’s only one way to learn how to really use Git: use it everyday. You are going to be using Git a lot in this book, and like any other skill, and the only way to get good at it is to practice. We’re going to give you a lot of practice: every chapter has exercises that pose a problem for you to solve. Don’t just skip over them—a lot of the learning happens when you solve the exercises. We included a solution to each exercise—don’t be afraid to peek at the solution if you get stuck! (It’s easy to get snagged on something small.) But try to solve the problem before you look at the solution. And definitely get it working before you move on to the next part of the book.
Read me
This is a learning experience, not a reference book. We deliberately stripped out everything that might get in the way of learning whatever it is we’re working on at that point in the book. And the first time through, you need to begin at the beginning, because the book makes assumptions about what you’ve already seen and learned.
We break things down, then build them back again.
We are fans of teasing things apart. This gives us the chance to focus on one aspect of Git at a time. We use a lot of visuals to explain what Git is doing when you perform any operation. We make sure you have a deep understanding of each aspect and the confidence to know when and how to use them. Only then do we start to bring things together, to explain the more complex ideas in Git.
We don’t exhaustively cover everything.
We use the 80/20 approach. We assume that if you are going for a PhD in Git, this isn’t going to be your only book. So we don’t talk about everything. Just the stuff that you’ll actually use, and that you’ll need to hit the ground running.
The activities are NOT optional.
The exercises and activities are not add-ons; they’re part of the core content of the book. Some of them are to help with memory, some are for understanding, and some will help you apply what you’ve learned. Don’t skip the exercises. The crossword puzzles are the only thing you don’t have to do, but they’re good for giving your brain a chance to think about the words and terms you’ve been learning in a different context.
The redundancy is intentional and important.
One distinct difference in a Head First book is that we want you to really get it. And we want you to finish the book remembering what you’ve learned. Most reference books don’t have retention and recall as a goal, but this book is about learning, so you’ll see some of the same concepts come up more than once.
The examples are as generic as possible.
Most tutorials for Git specifically target developers, and the examples usually involve code. We make no such assumptions about you. We’ve deliberately made the examples in this book generic yet interesting, fascinating—and downright fun. We’re certain you will be able to relate to them and learn how to use Git, no matter what kind of work you do.
Finally, we want you to learn about Git; we’re not looking to teach you how to type. To make things easier, we’ve placed all the example files on the web so you can simply download them. You’ll find instructions at https://i-love-git.com.
The Brain Power exercises don’t have answers.
For some of them, there is no right answer, and for others, part of the learning experience is for you to decide if and when your answers are right. In some of the Brain Power exercises, you will find hints to point you in the right direction.
Not all Test Drive exercises have answers.
For some exercises, we simply ask that you follow a set of instructions. We’ll give you ways to verify if what you did actually worked, but unlike other exercises, there are no right answers.
You’re going to have to install Git (macOS)
More than likely your computer doesn’t have Git installed, or if it does, it might not have the right version of Git installed. At the time of writing, Git was at version 2.34. While you don’t need to have the latest and greatest version of Git installed, we’ll need you to install verion 2.23 or later. Here’s how:
For macOS, open your browser and enter:
On this page you should see the macOS download links. If not, look under the Downloads section on the page.
Click the Download button for Git.
This page lists several ways to install Git. You can use a package manager like Homebrew, or you can get an installer.
If you choose to use the installer, download it. Then open the installation package in your downloads folder and follow the installation instructions.
Note
Note that you’ll need administrator privileges to install Git—if you commonly install apps, you should be fine; otherwise, ask your administrator for help.
Using the terminal to verify the installation
The Mac operating system ships with a built-in terminal. You can use the terminal to verify if your Git installation went well, and given that you are going to be using the terminal a lot in this book, you might as well get a practice session in. You’ll find the Terminal.app
in the Applications > Utilities
folder.
Note
You can also use Spotlight to search for the terminal.
When you open the Terminal.app
, you’ll be greeted with a terminal window and a prompt. Type git version
and you should see something like this:
Don’t worry if you’ve never worked with the terminal before. We have a whole section in Chapter 1 to get you up to speed with the commands you’ll need in this book.
You’re going to have to install Git (Windows)
For Windows, open your browser and enter:
Click the Download button for Git.
Choose to either save or run the executable. If the former, click to run the installer after you’ve downloaded it.
The installer window will appear on your screen. We ask that you stick to the defaults.
When the installer asks you to “Select Components,” make sure that “Windows Explorer integration,” “Git Bash Here,” and “Git GUI Here” are all checked.
Note
Note that you’ll need administrator privileges to install Git—if you commonly install apps, you should be fine; otherwise, ask your administrator for help.
Using Git Bash to verify the installation
As part of your Git installation on Windows, you also installed an application called Git Bash. You are going to be using Git Bash throughout this book as your command-line interface to Git, so let’s get a practice session in. Navigate using the Start button, and you should see Git Bash listed under the Git menu option. Click on that and you’ll be greeted with a terminal window and a prompt. Type git version
and you should see something like this:
Going forward, when we say “terminal” or “command line,” that’s your cue to start the Git Bash application. And worry not! If you are new to using the terminal, we’ve included a whole section in Chapter 1 to get you up to speed.
Note
Note to Linux users: We’re not worried about you; let’s be real, you know what you’re doing. Just grab the approriate distribution from https://git-scm.com.
You’re going to need a text editor (macOS)
Most of the exercises in this book involve using a text editor. If you have one that you prefer to use, feel free to skip this section. On the other hand, if you don’t have a text editor, or you trust us enough to want a suggestion, then we recommend using Visual Studio Code. This is a free, open source text editor from Microsoft. We love it because it ships with very nice defaults. This means you can start using it immediately, and it integrates well with Git.
Note
Yes, we know we just met, but we can dream, can’t we?
For macOS, using your browser, navigate to:
You should see a button to download the installer.
Click the Download button for Visual Studio Code for Mac. This will download a zip file to your Downloads folder.
Double-click the downloaded zip file to extract the application file. Drag the application file into the Applications folder.
Launch Visual Studio Code by double-clicking the application file in the Applications folder.
Type
Cmd-Shift-P
to see Visual Studio Code’s “Command Palette.” Type “shell command” and pick the “Shell Command: Install ‘code’ command in PATH” option:
That’s all there is to it! From now on, forward, anytime we ask that you fire up your text editor or edit a file, you are going to reach for Visual Studio Code. We recommend dropping a shortcut onto your Dock for easy access.
You’re going to need a text editor (Windows)
Windows ships with Notepad as its default text editor. We strongly advise against using Notepad—it has some idiosyncrasies that are best avoided. If you haven’t found a replacement yet, then we highly recommend Visual Studio Code from Microsoft. Visual Studio Code is a batteries-included text editor that can serve as an excellent replacement for Notepad and other text-editing needs.
For Windows, fire up your browser and go to:
You should see a button to download the Windows installer.
Click the Download button for Visual Studio Code for Windows.
Double-click the executable in your downloads directory. We recommend you accept all the defaults.
When the installer asks you to “Select Additional Tasks,” make sure to check “Register Code as an editor for supported file types” and “Add to PATH (requires shell restart).”
There you go! Anytime we ask you to “edit a file using your text editor,” that’s when you are going to reach for Visual Studio Code. Notepad begone!
You’re (definitely) going to need a GitHub account
If you don’t already have a GitHub account, then let’s get you set up. If you already have an account with GitHub for work, then we recommend you create a personal account just for this book. (This isn’t absolutely necessary, so use your discretion.)
To set up an account on GitHub, fire up your browser and type in the following:
You’ll see a “Sign up for GitHub” field that requires you to supply an email address.
Walk through the wizard, supplying an username and a strong password.
You can select the “Free” option. (Don’t worry—you can change this later if you like.)
You are all set! Just a few more steps, we promise!
Setting up a personal access token
GitHub requires you to set up a special token if you ever want to authenticate yourself using the command line. This is something you’ll need to do starting in Chapter 5, so we might as well get that knocked out.
Sign in to github.com using your username and password. Click on your profile icon in the top-right corner to reveal a drop-down menu. Select “Settings.”
On the next screen, look for “Developer settings” in the left-hand menu. Click that.
On the next screen, click on “Personal access tokens.” This will lead you to a screen that lets you create a token that you can authenticate with GitHub using the terminal.
You should see a “Generate new token” button in the top right-hand corner. Click that.
Next, you are required to supply a “Note” that serves as a reminder of why you created this token. We called ours
headfirst-git
. For the expiration period we picked 90 days. Finally, be sure to check the “repo” box to give this token “Full control of private repositories.”Note
If this book takes you longer than 90 days to finish (and we are sure it won’t), you’ll have to repeat this exercise. So giddyup! Time’s a-wasting!
GitHub will show you a final screen that reveals the token. Copy that access token and keep it somewhere secure—this gives you (or anyone else) access to your GitHub account. Treat it with care. If you lose the token you’ll have to do this whole exercise all over again.
A word on organizing your files and projects
Throughout this book, you are going to be working on a series of different projects. We recommend keeping your code organized by chapter. We also assume that you’ll be creating one folder per chapter, like this:
You should also visit:
There you’ll find instructions for downloading all the files (organized by chapter) that you’ll need. We suggest you download them and keep them within reach. Feel free to copy them when you need to—they only exist to save you a bunch of typing. We do ask that you follow all the instructions in the exercises and take the time to type out all the commands we ask you to. This will help you develop your muscle memory for working with Git and help things sink into your brain.
Note
Note that, for several exercises, we provide multiple versions for the same file. In these cases, we append a number at the end—for example, FAQ-1.md, FAQ-2.md, and so on. We’ll provide detailed instructions in every exercise on how to use these files, but we figured we’d point it out right now.
The technical review team
Meet our review team!
We were lucky enough to round up a powerhouse team of people to review this book, including senior developers, software architects, renowned public speakers, and prolific book authors.
These experts read every page, did the exercises, corrected our mistakes, and provided detailed commentary on every single page of this book. They also acted as our sounding board, letting us work through ideas, analogies, and narratives—even helping us think through how this book should be organized.
Every single reviewer here made huge contributions to this book and vastly improved its quality. We deeply appreciate the countless hours they spent poring over the manuscript. We remain indebted to them.
Note
While we aspire for this book to be error- and omission-free, we’ll be the first to admit that’s a lofty goal. Just know that any and all omissions are ours and ours alone.
Thank you!
O’Reilly Online Learning
For more than 40 years, O’Reilly Media has provided technology and business training, knowledge, and insight to help companies succeed.
Our unique network of experts and innovators share their knowledge and expertise through books, articles, and our online learning platform. O’Reilly’s online learning platform gives you on-demand access to live training courses, in-depth learning paths, interactive coding environments, and a vast collection of text and video from O’Reilly and 200+ other publishers. For more information, visit http://oreilly.com.
Acknowledgments
Writing a book is often viewed as a solitary activity. But no one is an island. I can only aspire to personify the values imparted upon me by my family, teachers, and mentors. My work is built on the shoulders of giants—technologists from the past and present who worked, and continue to work, tirelessly to make the world a better place. You may see my name on the cover, but a lot of the credit for this book goes to these individuals.
My editor:
My biggest thanks to my editor Sarah Grey. She read every chapter multiple times, did all the exercises, course-corrected when I ventured too deep into the weeds, and kept me on track to deliver this book to you in time. If you find yourself salivating at the delicious menu listings in this book, or getting teary-eyed when reading the poetry, well, the credit for all that goes to Sarah. She has been instrumental in bringing this book from early development all the way to production. I am truly blessed to have an editor like Sarah.
The O’Reilly team:
A big thanks to the entire O’Reilly Media team, including Kristen Brown for making sure that our book was production worthy, and to Sharon Tripp for the keen and astute eye when copyediting. And like me, if you are someone who routinely uses the index, you have Tom Dinse to thank.
I’d like to thank Melissa Duffield for being so supportive (and patient) throughout this process and Ryan Shaw for considering me for this project.
Much appreciation toward the O’Reilly online training team, specifically John Devins and Yasmina Greco for giving me a platform to teach Git (among other things) to thousands of developers around the world.
A shoutout to the Early Release team, who put out raw and unedited chapters for the audience on the O’Reilly platform to review as they were written. This gave a chance for many of our readers to submit errata and feedback that made this book just that much better.
Finally, I’d be remiss if I did not mention Elisabeth Robson and Eric Freeman. They took the time to review my work and ensure that it aligned with the vision that is the Head First series—not to mention gave some really useful InDesign tips—thank you!
Just when you thought there wouldn’t be any more acknowledgments*
Thanks to:
Jay Zimmerman, director of the No Fluff Just Stuff (NFJS) conference circuit. Thank you for giving me a shot a decade ago. This opened the door for me to speak at conferences throughout the United States and around the world and meet distinguished and accomplished individuals who, to this day, continue to inspire me. Public speaking also gave me the chance to teach and speak about Git, and my regular interactions with smart and talented audiences helped hone a lot of the material you’ll find in this book.
Venkat Subramaniam, world-famous speaker, teacher, consultant, prolific author with an uncanny ability to make the hard stuff fun, friend and mentor—you are an inspiration to me. I realize that I can only shoot for the moon and hope that I land among the stars.
Mark Richards, fellow author at O’Reilly, highly regarded architect and speaker around the world, and wonderful human being—you unwittingly set the wheels in motion for this book to happen.
Matthew McCullough and Tim Berglund, who a long time ago produced Mastering Git (https://www.oreilly.com/library/view/mccullough-and-berglund/9781449304737) and opened my eyes to the elegance of Git. I’ve been enamored since. You’ll always be my canaries.
The countless individuals who contribute to Git, and those who enrich the ecosystem around Git by writing detailed technical blog posts, creating informative videos, and answering questions on Stack Overflow—I am humbled by your work, and I hope that this book will be a valuable addition to your valiant efforts. Thank you.
My eternally patient, much better half, Michelle, who shouldered everything that needed to be done so I could focus on this book. Several of the narratives in this book come from her creative mind. I love you.
My family and my sisters, who (despite their fervent denials) forged me into the individual I am.
And finally, you, the readers. Your attention is a scarce resource, and I deeply appreciate the time you’ll spend with this book. Happy learning.
Now go on, Git!
Note
We noticed that they started to play the get-off-the-stage music, so we’re going to have to stop here.
* The large number of acknowledgments is because we’re testing the theory that everyone mentioned in a book acknowledgment will buy at least one copy, probably more, what with relatives and everything. If you’d like to be in the acknowledgments of our next book and you have a large family, write to us.
Get Head First Git now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.