Head First Git

Book description

What will you learn from this book?

Many people who use Git rely on "recipes"--copying and pasting commands they find on the internet without really understanding how Git actually works. But what do you do if you find yourself in a tight spot? You can't simply wing it. With this unique hands-on guide, you'll learn the ways of Git and have fun while doing it. Raju Gandhi peels back the layers to reveal the simple yet powerful engine that powers Git, so you'll understand not just the how but the why. You'll master branches, merges, commit messages, search, utilities, and more; learn best practices for collaborative work; and unlock the full potential of Git.

What's so special about this book?

If you've read a Head First book, you know what to expect--a visually rich format designed for the way your brain works. If you haven't, you're in for a treat. With this book, you'll learn Git through a multisensory experience that engages your mind rather than a text-heavy approach that puts you to sleep.

Publisher resources

View/Submit Errata

Table of contents

  1. Other books in O’Reilly’s Head First series
  2. Author of Head First Git
  3. Table of Contents (the real thing)
  4. How to use this Book: Intro
    1. Who is this book for?
      1. Who should probably back away from this book?
    2. We know what you’re thinking
    3. We know what your brain is thinking
      1. This must be important! Don’t forget it!
    4. Metacognition: thinking about thinking
      1. So just how DO you get your brain to treat Git like it’s a hungry tiger?
    5. Here’s what WE did
    6. Here’s what YOU can do to bend your brain into submission
    7. Read me
      1. We break things down, then build them back again.
      2. We don’t exhaustively cover everything.
      3. The activities are NOT optional.
      4. The redundancy is intentional and important.
      5. The examples are as generic as possible.
      6. The Brain Power exercises don’t have answers.
      7. Not all Test Drive exercises have answers.
    8. You’re going to have to install Git (macOS)
    9. Using the terminal to verify the installation
    10. You’re going to have to install Git (Windows)
    11. Using Git Bash to verify the installation
    12. You’re going to need a text editor (macOS)
    13. You’re going to need a text editor (Windows)
    14. You’re (definitely) going to need a GitHub account
      1. Setting up a personal access token
    15. A word on organizing your files and projects
    16. The technical review team
    17. O’Reilly Online Learning
    18. Acknowledgments
    19. Just when you thought there wouldn’t be any more acknowledgments*
  5. 1. Beginning Git: Get Going with Git
    1. Why we need version control
    2. Cubicle Conversation
      1. Got Git?
    3. Start your engines...
    4. A quick tour of the command line: knowing where you are with pwd
    5. More on the command line: creating new directories with mkdir
    6. (Even) More on the command line: listing files with Is
    7. More on the command line (almost there): changing directories with cd
    8. No argument there
    9. Cleaning up
    10. Creating your first repository
    11. Inside the init command
    12. Code Magnets
    13. Introduce yourself to Git
    14. How you will use Git
    15. Putting Git to work
    16. Meanwhile, back at the HawtDog Dating Service...
    17. Working with the HawtDawg Git repository
    18. Speaking of...
      1. Congratulations on your first commit!
    19. What exactly does it mean to commit?
    20. Look before you leap
    21. The three stages of Git
      1. Great question!
    22. Git in the command line
    23. A peek behind the curtain
    24. The multiple states of files in a Git repository
      1. A typical day in the life of a new file
      2. The object database is the “source of truth”
      3. BE Git
    25. The index is a “scratch pad”
    26. Computer, status report!
      1. Whoa, easy tiger!
    27. You’ve made history!
      1. Crossword Init
      2. Code Magnets Solution
      3. BE Git Solution
      4. Crossword Init Solution
  6. 2. Branching Out: Multiple Trains of Thought
    1. It all started with an email
      1. But things didn’t quite pan out...
      2. What would you do if you were Norm?
    2. Updating the restaurant menu
    3. First things first
      1. Very astute!
    4. Choices...so many choices!
    5. Switching tracks
    6. Back at the ’80s Diner
    7. Send it back!
      1. Code Magnets
    8. Visualizing branches
    9. Branches, commits, and the files contained within
      1. BE Git
    10. Cubicle Conversation
    11. Working in parallel
      1. BE Git
    12. What is a branch, really?
    13. Switching branches, or switching directories?
    14. Some branches are more equal than others
    15. Bring it in!
    16. Read the #&$!@ manual (git branch edition)
    17. Making the fall menu official
    18. Some merges are fast-forward
    19. It doesn’t quite work the other way
    20. A little more Git setup
    21. It’s almost Thursday!
    22. Wait! You moved?
    23. It’s almost Thursday! (continued)
    24. It’s a merge commit
    25. Merge commits are kinda special
    26. Things don’t always go so smoothly
    27. I am so conflicted!
    28. I am so conflicted! (Ooof! Almost there)
    29. Cleaning up (merged) branches
      1. The answer to your question lies in the commit history.
    30. Deleting unmerged branches
    31. A typical workflow
      1. Git branch “crossword puzzle”
      2. Code Magnets Solution
      3. BE Git Solution
      4. BE Git Solution
      5. Git branch “crossword puzzle” Solution
  7. 3. Looking Around: Investigating Your Git Repository
    1. Brigitte’s on a mission
    2. Commits aren’t enough
    3. Mirror, mirror on the wall: who is the prettiest log of all?
    4. How does git log work?
    5. Making git log do all the work
    6. What diff-erence does it make?
    7. Visualizing file differences
    8. Visualizing file differences: one file at a time
    9. Visualizing file differences: one hunk at a time
    10. Making diffs easier on the eyes
    11. Diffing staged changes
    12. Diffing branches
    13. Diffing branches (we are there!)
    14. Diffing commits
    15. What does the diff for a new file look like?
      1. A Diff-icult Crossword
      2. A Diff-icult Crossword Solution
  8. 4. Undoing: Fixing Your Mistakes
    1. Planning an engagement party
    2. An error in judgment
    3. Cubicle conversation
    4. Undoing changes to the working directory
    5. Undoing changes in the index
    6. Deleting files from Git repositories
    7. Committing to delete
    8. Renaming (or moving) files
    9. Editing commit messages
      1. Aren’t you the observant one!
    10. Renaming branches
    11. Making alternative plans
      1. HEAD Tells All
    12. The role of HEAD
    13. Referencing commits using HEAD
    14. Traversing merge commits
    15. Undoing commits
    16. Removing commits with reset
    17. The three types of reset
      1. git reset --soft
      2. Using git reset (or git reset --mixed)
      3. git reset --hard
    18. Congratulations, you time traveler, you!
    19. Another way to undo commits
    20. Reverting commits
    21. Aaaaand that’s a wrap!
      1. Undo Crossword
      2. Undo Crossword Solution
  9. 5. Collaborating with Git - Part I: Remote Work
    1. Another way to a Git repository: cloning
    2. Hosting a Git repository
    3. Setting up: forking repositories (a sidebar)
    4. Ready, set, clone!
    5. It’s just another Git repository
    6. What happens when you clone?
    7. Git is distributed
    8. Another bit of Git configuration
    9. Pushing changes
    10. Verifying if the push worked
    11. Knowing where to push: remotes
    12. No photographs, please: public versus private commits
    13. Public versus private commits (continued)
    14. Standard operating procedure: branches
    15. Merging branches: option 1 (local merges)
    16. A quick note on GitHub’s interface
    17. Pushing local branches
    18. Merging branches: option 2 (pull requests)
    19. Creating pull requests
    20. Creating pull requests (Yep! Almost there)
    21. A brand-new, shiny pull request
    22. Pull requests or merge requests?
    23. Merging a pull request
    24. What’s next?
      1. A Pushy Puzzle
      2. A Pushy Puzzle Solution
  10. 6. Collaborating with Git - Part II: Go, Team, Go!
    1. Cubicle conversation
    2. Working in parallel
    3. Working in parallel...in Gitland
    4. Cubicle conversation (continued)
    5. Collaborating, Git style
    6. The setup for two collaborators on GitHub
    7. Our setup so far
      1. Two-player setup
      2. One-player setup
    8. Cubicle conversation (continued)
    9. Falling behind the remote
    10. Cubicle conversation (continued)
    11. Catching up with the remote (git pull)
    12. Introducing the middlemen, aka remote tracking branches
    13. Reason 1 for remote tracking branches: knowing where to push
      1. Remote tracking branch after you push
    14. Pushing to the remote: summary
    15. Fetching remote tracking branches
    16. Reason 2 for remote tracking branches: getting (all) updates from the remote
    17. Git branch flag soup
    18. Cubicle conversation (continued)
    19. Collaborating with others
      1. Git push/pull and remote tracking branches
    20. Collaborating with others: summary
    21. Reason 3 for remote tracking branches: knowing you need to push
    22. Reason 4 for remote tracking branches: getting ready to push
    23. Reason 4 (still going)
    24. Reason 4 (Yep! Almost there!)
    25. git pull is git fetch + git merge!
    26. Use git fetch + git merge. Avoid git pull.
    27. The ideal scenario
    28. A typical workflow: getting started
    29. A typical workflow: getting ready to merge
    30. A typical workflow: merge locally, or issue pull requests?
    31. A typical workflow visualized
    32. Cleaning up remote branches
      1. Collaborative Crossword
      2. Collaborative Crossword Solution
  11. 7. Searching Git Repositories: Git a Grep
    1. Taking things to the next level
    2. A walk through the commit history
    3. Cubicle conversation
    4. Seeing who changed what and when with git blame
    5. Using git blame
    6. git blame using Git repository managers
    7. A few more details about git blame
    8. Searching Git repositories
    9. Searching Git repositories with grep
    10. git grep options
      1. Case-insensitive search
      2. Displaying line numbers
      3. List only filenames
    11. The git grep flags combo
    12. Where git blame falls short
    13. git log’s “pickaxe” capability (-S)
    14. git log -S versus blame
    15. Using the “patch” flag with git log
    16. Using the “patch” flag with git log (almost there)
    17. git log’s other “pickaxe” flag (-G)
    18. Searching commit messages
    19. Git log flag soup
    20. What does it mean to check out a commit?
    21. Checking out commits
    22. Detached HEAD state
    23. The moral of the detached HEAD state
    24. Cubicle conversation
    25. Searching for commits using git bisect
    26. Using git bisect
    27. Finishing git bisect
      1. Searching for Clues
      2. Searching for Clues Solution
  12. 8. Making your life Easier with Git: #ProTips
    1. Configuring Git
    2. The global .gitconfig file
    3. Project-specific Git configuration
    4. Listing your Git configuration
    5. Git aliases, aka your personal Git shortcuts
    6. Tweaking the behavior of Git aliases
    7. Telling Git to ignore certain files and folders
    8. The effects of a .gitignore file
    9. Managing the .gitignore file
    10. A sample .gitignore file
    11. Commit early, commit often
    12. Write meaningful commit messages
    13. The anatomy of a good commit message
    14. The anatomy of a good commit message: headers
      1. Code Magnets
    15. The anatomy of a good commit message: bodies
    16. Fussy much?
      1. A shoutout
    17. Create helpful branch names
    18. Integrate a graphical user interface into your workflow
      1. The command line versus a GUI
      2. Congratulations!
      3. Configuration Crossword
      4. Code Magnet Solution
      5. Configuration Crossword Solution
  13. A. Leftovers: The Top Five Topics We Didn’t Cover
    1. #1 Tags (remember me forever)
    2. #2 Cherry-pick (copying commits)
    3. #3 Stashes (pseudo-commits)
    4. #4 reflog (reference log)
    5. #5 rebase (another way to merge)
      1. This isn’t goodbye!
  14. Index

Product information

  • Title: Head First Git
  • Author(s): Raju Gandhi
  • Release date: January 2022
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781492092513