Version First Edition

Learn and Master Git!

Chances are if you’re involved with software development you’ve heard of and have used Git at some point in your life. Version control systems are critical for any successful collaborative software project. Git is both simple to start using and accommodating for the most complex tasks with version control. Even seasoned Git users hit roadblocks on how to handle common situations.

Mastering Git is here to help! This book is the easiest and fastest way to get hands-on experience with using Git for version control of your projects.

Who This Book Is For

This book is for anyone who would like to leverage the power of version control with Git in their software development process. The book starts with a gentle introduction, then moves on to more complicated scenarios, including merge conflicts, rebasing and more.

Topics Covered in Mastering Git

  • Crash course in Git: All of the basics of Git that every software craftsman should know. Understand how to set up Git, committing, ignoring files, etc.
  • Branching/Merging/Pushing: The whole point of Git is collaboration and this covers everything to work with others.
  • How Git actually works: After using Git for a while it’s good to discover the whys behind all of the things.
  • Rebasing: Rebasing and squashing doesn’t have to be scary; it’s quite a useful and advanced way of merging code to support your collaborative workflow.
  • Undoing what you’ve done: Most frustration with Git comes from not being able to undo something that you’ve screwed up. But Git has lots of ways you can go back and recover from a weird merge or commit state.
  • Workflows in Git: Working with Git requires some rules to make sure things go smoothly across development teams. Learn the most common workflows and how to decide which one to use.

One thing you can count on: after reading this book, you’ll be well-prepared to use Git in your own software development workflow!

Before You Begin

This section tells you a few things you need to know before you get started, such as what you’ll need for hardware and software, where to find the project files for this book, and more.




Section I: Beginning Git

This first section is intended to get newcomers familiar with Git. It will introduce the basic concepts that are central to Git, how Git differs from other version control systems, and the basic operations of Git like committing, merging, and pulling.

You may discover things in this section you didn’t quite understand about Git, even if you’ve used Git for a long time.

Learn how to get started with Git, the differences between platforms, and a quick overview of the typical Git workflow.


It’s quite common to start by creating a copy of somebody else's repository. Discover how to clone a remote repo to your local machine, and what constitutes "forking" a repository.


A Git repo is made up of a sequence of commits—each representing the state of your code at a point in time. Discover how to create these commits to track the changes you make in your code.


Before you can create a Git commit, you have to use the “add” command. What does it do? Discover how to use the staging area to great effect through the interactive `git add` command.


Sometimes, there are things that you really don’t want to store in your source code repository.


There’s very little point in creating a nice history of your source code if you can’t explore it. You’ll discover the versatility of the `git log` command—displaying branches, graphs and even filtering the history.


The real power in Git comes from its branching and merging model. This allows you to work on multiple things simultaneously. Discover how to manage branches, and exactly what they are in this chapter.


You’ve been working hard on your local copy of the Git repository, and now you want to share this with your friends. See how you can share through using remotes, and how you can use multiple remotes at the same time.


If you are starting a new project, and want to use Git for source control, you first need to create a new repository.


Branches in Git without merging would be like basketball without the hoop—fun, sure, but with very little point. In this chapter you’ll learn how you can use merging to combine the work on multiple branches back into one.


Section II: Advanced Git

This section dives deeper into the inner workings of Git, what particular Git operations actually do, and will walk you through some interesting problem-solving scenarios when Git gets cranky. You’ll build up some mental models to understand what’s going on when Git complains about things to help you solve similar issues on your own in the future.

If you've been using Git for a while, you might be wondering how it actually works. Discover how Git is built on top of a simple key-value store-based file system, and what power this provides to you.


Merging isn't always as simple as it might first appear. In this chapter you will learn how to handle merge conflicts — which occur when Git cannot work out how to automatically combine changes.


Git stashes offer a great way for you to create a temporary snapshot of what you're working on, without having to create a full-blown commit. Discover when that might be useful, and how to go about it.


Rebasing is poorly understood, although it can be an incredibly powerful tool. In this chapter, we’ll cover what happens behind the scenes when you rebase and set you up for some useful applications of rebasing in the coming chapters.


Rebase is a whole lot more powerful than just as a replacement for merge. It offers the ability to completely rewrite the history of your Git repo.


Gitignore is easy right? If you've been using it for a while you'll know that isn't always true. Discover how you can fix problems with gitignore such as handling files that have been accidentally committed to the repository.


One of the common questions associated with Git is "how can I get out of this mess?" In this chapter you'll learn about the different "undo" commands that Git provides — what they are and when to use them.


Section III: Git Workflows

Now that you understand how Git works and how to use some of the advanced features, you need to learn how to incorporate Git into your software development lifecycle. There are established best practices and several formal Git workflows out there.

Those formal Git workflows, well, they’re all good, and in some cases, they’re all bad. It depends what you want to accomplish in your repo, and how your own team works. GitFlow is one of the most popular branching strategies, but there are alternative models that work well in many situations. This section will introduce you to these workflows and branching models, and explain what problems they solve and what problems they create.

This model means you work in master all the time. Although this might seem terrifying, it actually works rather well for small teams with infrequent commits.


Feature branches are used to create new features in your code and then merged to master when they're done.


A popular method to manage your team’s development workflow. In fact, there are even plugins for IDEs that support this Git workflow.


A popular method to manage your team’s development workflow. In fact, there are even plugins for IDEs that support this Git workflow.



Meet the team


Who is this book for

This book is for anyone who would like to leverage the power of version control with Git in their software development process.

Concepts covered in this book

  • Crash course in Git
  • Branching/Merging/Pushing
  • How Git actually works
  • Rebasing
  • Workflows in Git

Version history

First Edition ·

v1.0 · Aug 24 2020 · Jawwad Ahmad & Chris Belanger

Mastering Git

By Jawwad Ahmad & Chris Belanger

Learn how Git works under the hood, master workflows, branching, merging and rebasing your work for easy and successful project collaboration!

Read for Free with an Ultimate Pro Subscription* * Includes this and all other books in our online library See all benefits
Buy Individually $59.99* *Includes access to all of our online reading features.
See buying options
Hide buying options

All videos. All books.
One low price.

A subscription is the best way to learn and master mobile development — plans start at just $19.99/month!

Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.