Everything You'll Need to Know About Git



3 hours, 23 minutes CC
Everything You'll Need to Know About Git

Course Description

Never run into an unsolvable Git problem again. Create and manage repos, branch for parallel development, and resolve conflicts with merge and rebase. Learn advanced git abilities like interactive rebasing for cleaning up commit history, bisecting to locate problematic commits, worktrees, and the reflog. By understanding Git's architecture and inner workings, you'll be able to handle any Git problem with confidence and become an indispensable asset to any large project.

This course and others like it are available as part of our Frontend Masters video subscription.


Course Details

Published: May 6, 2024


Learn Straight from the Experts Who Shape the Modern Web

Your Path to Senior Developer and Beyond
  • 200+ In-depth courses
  • 18 Learning Paths
  • Industry Leading Experts
  • Live Interactive Workshops
Get Unlimited Access Now

Table of Contents


Section Duration: 14 minutes
  • Introduction & man Pages
    ThePrimeagen introduces the course and mentions that they will not cover every single command in Git, but will focus on teaching the most important ones. He also emphasizes the importance of using the manual pages (man pages) to learn about Git commands and demonstrates how to navigate and search within the man pages.
  • What is Git
    ThePrimeagen introduces the concept of Git as a distributed version control system. He explains the difference between centralized and distributed version control systems and highlights the benefits of using Git. The two levels of Git commands (porcelain and plumbing) and key terms such as repo, commit, index, staging, and working tree are also covered in this lesson.
  • git config
    ThePrimeagen discusses the importance of configuring Git and explains how Git's config works. He explains that Git config is similar to JavaScript's object design, with global and local settings. Setting the user.name and user.email in the Git config for creating commits is also demonstrated in this lesson.

Git Basics

Section Duration: 23 minutes
  • Creating a New Repo
    ThePrimeagen explains how to create a new git repository using the "git init" command. He demonstrates the process by creating a new repository and shows the resulting .git folder that is created. He also discusses the purpose of the .git folder, how it contains all the data structures, and the repository's history.
  • Basics & Commit SHA
    ThePrimeagen explains the basic Git commands of add, commit, and status. He demonstrates how to create a file, add it to the staging area, commit it with a message, and check the status of the repository. The Git log command and how to use the options --graph and --decorate to view the commit history are also demonstrated. The concept of SHA (Secure Hashing Algorithm) and how it is used to uniquely identify commits is also discussed in this lesson.
  • Diving into the Commit SHA
    ThePrimeagen walks through the process of finding and accessing a specific commit in the Git folder. Students are encouraged to use the "find" command to locate the commit and then use the "cat-file -p" command to view the contents of the commit. He also emphasizes that all of Git's state is stored in these files and demonstrates how to use the command to access the contents of a specific file within the commit.
  • Commit Graph: Tree & Parent
    ThePrimeagen demonstrates how to explore the contents of a commit using the `git cat-file -p` command. He explains the concept of a tree, which represents a directory, and a blob, which represents a file. Git stores the entirety of each file in every commit, rather than just the changes.

Branching, Merging, & Rebasing

Section Duration: 44 minutes
  • Config & Locations
    ThePrimeagen demonstrates how to use the `git config` command to add, list, and remove configuration values in Git. He shows how to add values to the config file using different scopes (global and local), how to list and retrieve specific values, and how to remove values and sections from the config file. How to rename the default branch from "master" to "trunk" using a global setting is also demonstrated.
  • Branching
    ThePrimeagen introduces the concept of branching in Git and explains that branching allows for separate development and experimentation without affecting the main line of code. He also demonstrates how to create a branch, switch between branches, and view the branch details.
  • Merge
    ThePrimeagen explains the concept of merging in Git and discusses the two different outcomes of a merge - one with a merge commit and one without a merge commit. He also explains the concept of the best common ancestor and how Git combines the histories of two branches during a merge. The process of merging branches using the `git merge` command and examples of merge commits and fast-forward merges are also covered in this segment.
  • Rebase
    ThePrimeagen explains the concept of rebase and its benefits and demonstrates how rebase allows you to update your set of changes and have them properly in line with the current reality of the repository. He also explains the basic steps of performing a rebase and warns about altering the history of public branches.
  • HEAD & reflog
    ThePrimeagen demonstrates how the "head" pointer changes when switching branches and shows the contents of the "head" file in the Git repository. The "reflog" command, which shows the history of branch changes, and how it is stored in the Git logs folder is also discussed. He also demonstrates how to view the reflog and provides an example of using the "reflog -3" command to display the last three entries.
  • reflog Exercise & Cherry Pick
    ThePrimeagen guides students through a series of tasks including creating a branch called "Baz" off of the "trunk" branch, adding a commit to the "Baz" branch in a new file, switching back to the "trunk" branch, deleting the "Baz" branch, and then recovering the deleted branch using Git commands. He also introduces the concept of using "cherrypick" to selectively merge a specific commit into a branch.

Working with Remote Repositories

Section Duration: 18 minutes
  • Remote Git & fetch
    ThePrimeagen explains the concept of remote Git and how to add a remote repository to your local repository. He demonstrates how to initialize a new repository, add a remote repository using the "git remote add" command, and fetch the changes from the remote repository using "git fetch". How to merge the changes from the remote repository into the local repository using "git merge" or "git pull" is also demonstrated in this lesson.
  • Pull
    ThePrimeagen explains how to use the "git pull" command to fetch and merge changes from a remote branch into your local branch. He discusses the importance of setting tracking information for branches and demonstrates how to do it. His preference for using the "git rebase" command to keep a clean and organized commit history and the benefits of this approach are also discussed in this lesson.
  • Push
    ThePrimeagen explains how to push changes from a local branch to a remote repository using the "git push" command and demonstrates the process by making changes to a branch called "bar" and pushing those changes to a remote repository called "hello git". He also discusses tracking branches, the importance of properly naming remotes, and briefly mentions alternative strategies for handling changes when pulling from a remote repository, such as stashing or using work trees.

Conflict Resolution

Section Duration: 55 minutes
  • Stashing
    ThePrimeagen discusses a stack of temporary changes called "stash", and demonstrates how to push changes to the stash, list and show stashes, and pop stashes. He also provides a problem for the students to practice using stash by making changes to different files in the "upstream" and "remote" branches.
  • Resolving Conflicts with Merge
    ThePrimeagen demonstrates how to use Git stash to save and retrieve changes when pulling in new changes from upstream. He also covers merging and squashing, which allows you to combine multiple commits into a single commit with a custom message. The lesson also touches on conflicts and the importance of manually editing the diffs to understand why conflicts can occur and how to resolve them.
  • Resolving Conflicts with Rebase
    ThePrimeagen creates a conflict in a Git repository and then shows how to resolve the conflict manually using rebase to choose which changes to keep and committing the resolved conflict. The difference between merge and rebase and how conflicts can arise when rebasing is also discussed in this lesson.
  • Rebasing Practice
    ThePrimeagen demonstrates how to create a conflict using the rebase command instead of the merge command. He makes changes to the "Hello Git" and "bar.md" files in both the local and remote branches, and then performs a rebase on the remote branch. He also discusses the potential danger of using rebase, as it can result in the complete removal of a commit if not handled carefully.
  • Potential Problems with Rebase
    ThePrimeagen provides an example where two branches have conflicting changes and walks through the process of resolving the conflict by choosing the desired changes. He also highlights the potential problems and frustration of encountering the same conflict multiple times when using rebase.
  • Reuse Recorded Resolutions
    ThePrimeagen discusses the use of the "rerere" option in Git to resolve conflicts more easily and explains how to enable "rerere" locally or globally. He also explains that, with "rerere" enabled, git will automatically remember how a conflict was previously handled and replay the decision the next time the conflict occurs.
  • Ours & Theirs
    ThePrimeagen discusses the differences between "ours" and "theirs" when utilizing rebase and merge. He also demonstrates how to resolve a conflict by selecting either "ours" or "theirs" changes.
  • Interactive Rebase
    ThePrimeagen demonstrates how to use interactive rebase to squash multiple commits into one. He also shares their personal workflow for squashing commits and pushing changes to a remote repository.

Git Tools & Techniques

Section Duration: 41 minutes
  • Searching Git Logs
    ThePrimeagen discusses searching through git logs to find the commit that introduced a bug or issue in a codebase. He briefly explains that git bisect is useful when there are a large number of commits and it is not known when the issue occurred. How to use git log and grep to search for specific keywords or files in the commit history to narrow down the search for the problematic commit is also demonstrated in this lesson.
  • Bisect
    ThePrimeagen explains how to use the `git bisect` command to search through Git commits and find a bug or regression. He discusses the properties of bisecting, such as cutting the search space in half with each test, and demonstrates how to use the `git bisect` command to find the commit where the bug occurred. How to automate the process using the `git bisect run` command is also demonstrated in this lesson.
  • Revert
    ThePrimeagen explains the concept of reverting changes in Git. He demonstrates how to revert a commit using the "git revert" command and shows how conflicts can arise during the process. ThePrimeagen also highlights the importance of using squashed rebase to simplify the process of reverting changes.
  • Reset
    ThePrimeagen explains the different uses of the "git reset" command and demonstrates how to use "git reset soft" to walk back a commit and keep the changes in the working tree and index. He also shows how to use "git reset hard" to completely destroy changes in the working tree and index. Using "git commit --amend" to retroactively apply current changes to the previous commit is also discussed in this lesson.
  • Worktrees
    ThePrimeagen introduces the concept of worktrees as a solution to the limitations and inconveniences of using stash in Git. He explains that a worktree is a linked working tree, separate from the main tree, that allows for easy switching between branches without the need for stashing or committing changes. A demonstration of how to create and manage WorkTrees, highlighting their benefits and potential drawbacks is also provided in this lesson.
  • Tags & Other Tools
    ThePrimeagen explains how to use tags in Git and demonstrates how to create, delete, list, and checkout tags. He also mentions that tags show up in the log and can be pulled and pushed just like branches. The tool "fugitive" and some of its features, such as staging and committing changes, pushing to a remote, stashing, and interactive rebasing are also introduced in this lesson.

Wrapping Up

Section Duration: 5 minutes
  • Wrapping Up
    ThePrimeagen wraps up the course by answering student questions about Git, including the use of Git Large File Storage (LFS) for optimizing large files, the preference for clean history when reverting changes, techniques for contributing to open source projects, and handling ENV files in a repository. He also mentions a plugin for VIM called Cloak, which adds stars to an ENV file to prevent accidental leakage, and explains how to create a personal gitignore file using Git info exclude.
This git course is really excellent. I use git every day and knew the basics well enough, but this really helped solidify what’s under the hood rather than go through the motions.
Javid G.

Javid G.

Javid G.

Amazing course! Easy to understand. A profound, and a great choice for us as developers!
Diego Escaño

Diego Escaño

Diego Escaño

Even after all my experience with Git, I learned a lot of really cool stuff. Highly recommend.
Stephen Greco

Stephen Greco

Senior Software Engineer & Tech Lead

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now