Git for Programmers

Book description

Learn to track, branch, merge, and manage code revisions for real-world development scenarios

Key Features

  • Master Git and maintain your projects better through version control
  • Get to grips with Git’s typical workflows, advanced functions, and their implementations
  • Learn the key Git commands to better manage your repository

Book Description

Whether you’re looking for a book to deepen your understanding of Git or a refresher, this book is the ultimate guide to Git.

Git for Programmers comprehensively equips you with actionable insights on advanced Git concepts in an engaging and straightforward way. As you progress through the chapters, you’ll gain expertise (and confidence) on Git with lots of practical use cases.

After a quick refresher on git history and installation, you’ll dive straight into the creation and cloning of your repository. You’ll explore Git places, branching, and GUIs to get familiar with the fundamentals. Then you’ll learn how to handle merge conflicts, rebase, amend, interactive rebase, and use the log, as well as explore important Git commands for managing your repository.

The troubleshooting part of this Git book will include detailed instructions on how to bisect, blame, and several other problem handling techniques that will complete your newly acquired Git arsenal.

By the end of this book, you’ll be using Git with confidence. Saving, sharing, managing files as well as undoing mistakes and basically rewriting history will be a breeze.

What you will learn

  • Create remote and local repositories and learn how to clone them
  • Understand the difference between local and remote repositories
  • Use, manage, and merge branches back into the main branch
  • Utilize tools to manage merge conflicts
  • Manage commits on your local machine through interactive rebasing
  • Use the log to gain control over all the data in your repository
  • Use bisect, blame, and other tools to undo Git mistakes

Who this book is for

If you have basic understanding of Git and want to strengthen your command over advanced techniques and navigate different functions, this book is for you. Knowing the fundamentals of Git will help you get the most out of this book, but beginners willing to invest some extra effort will be able to follow along as well.

Table of contents

  1. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the color images
      2. Conventions used
    4. Get in touch
    5. Share your thoughts
  2. Introduction
    1. About this book
    2. Version control
    3. About the code examples
    4. Just a brief history
    5. Tools for working with Git
      1. GitHub, et al.
      2. GUIs and the command line
      3. The command line
      4. Making the command line pretty
      5. Visual Studio 2019
      6. Getting Visual Studio for free
      7. GitHub Desktop
    6. Getting Git
      1. Getting Git on Windows
      2. Getting Git on a Mac
      3. Getting Git on Linux
      4. Checking your version
    7. Configuring Git – the command line
    8. Configuring Git – Visual Studio
    9. Configuring Git – GitHub Desktop
    10. Summary
  3. Creating Your Repository
    1. Creating your repository
      1. Creating your repository on GitHub first
      2. Cloning to your computer – command line
      3. Cloning to your computer – visual studio
      4. Cloning to your computer – GitHub for Desktop
      5. Creating a project
    2. Git pull
      1. Pulling down using GitHub Desktop
        1. Pulling down to Visual Studio
    3. Push me, pull you
      1. Pushing to the server
      2. Downloading the changes at the command line
        1. Downloading the changes using GitHub Desktop
    4. Starting at the command line
      1. Pulling to GitHub Desktop
      2. Pulling to Visual Studio
    5. Commits – best practices
      1. How often should I commit?
      2. Keep your commit history clean
      3. A note on commit messages
      4. When the title isn't enough
    6. Summary
  4. Branching, Places, and GUIs
    1. Five places
      1. The work area
      2. The index/staging area
      3. Skipping the staging area
      4. Visual Studio
      5. GitHub Desktop
      6. Local and remote repositories
      7. The stash
    2. Branches
      1. Programmer 1 (CommandLine) and calculator
        1. Pushing the new branch
        2. Examining origin
        3. Adding commits to a branch
      2. The Book branch – Git within Visual Studio
      3. Committing with GitHub Desktop
      4. Status
        1. What's on origin?
      5. Adding more commits
      6. Examining your commits
    3. Summary
    4. Challenge
    5. Answer
  5. Merging, Pull Requests, and Handling Merge Conflicts
    1. Merging overview
      1. Book
    2. What's in that push?
      1. Visual Studio
      2. Details, details
    3. GitHub Desktop
      1. Push it already
      2. Visual Studio
    4. Merge conflicts
      1. Merging from the command line
      2. Fast forward
      3. True merge
    5. Avoiding conflicts
    6. Summary
    7. Challenge
    8. Answer
      1. Task #1: Set up a new repository and clone it to two different folders
      2. Task #2: Have one person populate the main branch with the beginnings of UtilityKnife, commit the changes, and push it
      3. Task #3: Each programmer creates a feature branch. Each programmer then puts the beginning of their feature into their branch, committing frequently (more frequently than you would in "real life")
        1. Sara and the Calculator
      4. Task #4: Merge the main branch into the feature branch frequently to ensure that if there are conflicts, you catch them early
      5. Task #5: John is building the temperature converter. Have him "borrow" code from the calculator. See if there are merge conflicts
  6. Rebasing, Amend, and Cherry-Picking
    1. Rebasing
      1. How Git does it
      2. Getting your head around it
      3. Rebase early and rebase often
      4. Rebase locally only
      5. Rebasing in practice
      6. Seeing the rebase at work
      7. Conflicts
    2. Amending
    3. Cherry-picking
      1. Visual Studio cherry-picking
    4. Summary
    5. Challenge
    6. Answer
      1. Creating a new repository on GitHub
      2. Creating two feature branches with fake programmers
      3. Frequent rebasing
      4. Amending a commit to add a file
      5. Amending a commit to change the message
      6. Cherry-picking one commit onto main
  7. Interactive Rebasing
    1. Interactive rebasing at work
      1. Creating our example
      2. Using interactive rebase to clean up your commits
    2. Summary
    3. Challenge
  8. Workflow, Notes, and Tags
    1. Standard workflow
    2. Mirroring your repo
      1. Replicating an existing repo
      2. Adding and showing notes
      3. Tags
        1. Pointing to a different tag
    3. Summary
    4. Challenge
  9. Aliases
    1. Aliases
    2. Summary
    3. Challenge
    4. Answer
  10. Using the Log
    1. Getting started with log
      1. The LogDemo program
      2. Visual Studio
      3. GitHub Desktop
    2. log at the command line
      1. Which files changed?
      2. What changed in each file?
      3. diff
      4. Visual Studio
      5. What changed in this file over time?
      6. Search
      7. Where are my commits?
    3. Summary
    4. Challenge
    5. Answer
      1. Create a new repository
      2. Add at least 6 commits
      3. Find the names of every file changed in each commit
      4. Find what changed in a given file over time
      5. Find all the files you committed in the past hour (or whatever time increment makes sense)
  11. Important Git Commands and Metadata
    1. Stash
    2. Clean
    3. Metadata
    4. Summary
    5. Challenge
    6. Answer
  12. Finding a Broken Commit: Bisect and Blame
    1. Blame
    2. Challenge
  13. Fixing Mistakes
    1. You wrote the wrong message in the last commit
    2. You forgot to add changed files from your last commit
    3. Problems with the order of commits or their messages
    4. You need to undo changes made in a commit
    5. You misnamed your branch
    6. You committed to the wrong branch
    7. You trashed a file in a previous commit
    8. You messed up the remote by pushing a broken branch
    9. Quiz
    10. Answers
      1. What do you do if you left out a changed file in the last commit?
      2. What do you do if you committed to the wrong branch?
      3. What do you do if you corrupted a file in a previous commit?
      4. What do you do if you need to undo changes made in a commit?
      5. What do you do if you trashed Master by pushing a broken branch?
  14. Next Steps
  15. Other Books You May Enjoy
  16. Index

Product information

  • Title: Git for Programmers
  • Author(s): Jesse Liberty
  • Release date: June 2021
  • Publisher(s): Packt Publishing
  • ISBN: 9781801075732