DevOpsLesson
DevOpsLesson

Free, comprehensive DevOps tutorials and learning roadmaps. Master Docker, Kubernetes, CI/CD, and more.

Stay Updated

Get notified about new tutorials and features.

Tutorials

  • What is DevOps?
  • Docker Tutorial
  • Terraform Tutorial
  • CI/CD Pipeline
  • All Tutorials

Roadmaps

  • DevOps Engineer
  • Cloud Engineer
  • SRE Path
  • All Roadmaps

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 DevOpsLesson. All rights reserved.

DOCKERKUBERNETESTERRAFORMAWSCI/CDLINUXGITDEVOPS ROADMAPCLOUD ROADMAPSRE ROADMAPGIT CHEATSHEETDOCKER CHEATSHEETK8S CHEATSHEETTF CHEATSHEETLINUX CHEATSHEETDOCKERFILE LINTERYAML VALIDATORCRON PARSERREGEX TESTER

Git Tutorial

Introduction to Git
Installing Git
Git Basics
Git Branching
Git Merging
Git Rebasing
Git Remote
Git Stash
Undoing Changes in Git
Git Tagging
GitHub Workflow with Git
Advanced Git
Git Hooks
Git Workflows
Git Aliases and Configuration
Git Submodules
Git Commit Messages

Advanced Git

PreviousPrev
Next

Explore useful advanced Git tools including cherry-pick, bisect, reflog, submodules, hooks, and aliases for smarter daily workflows.

Why Learn Advanced Git?

Once you know commits, branches, merges, and remotes, the next step is learning the tools that save time during debugging, recovery, and automation. Advanced Git commands are not used every hour, but when you need them, they can be incredibly valuable.

In this lesson, you will meet six high-impact concepts:

  • cherry-pick
  • bisect
  • reflog
  • submodules
  • hooks
  • aliases

Tip: Advanced Git is less about memorizing every option and more about recognizing which tool fits the situation.

Cherry-Pick

git cherry-pick copies the change introduced by an existing commit and applies it to your current branch.

This is useful when you want one specific fix without merging a whole branch.

Example:

git switch release/1.2
git cherry-pick a1b2c3d

A common real-world use case is backporting a bug fix from main to an older release branch.

When to Use It

Use cherry-pick when:

  • a single commit should move to another branch
  • you want to avoid merging unrelated work
  • you are backporting a hotfix

Be careful not to overuse it, because duplicated commits across branches can make history harder to follow.

Bisect

git bisect helps you find which commit introduced a bug by performing a binary search through history.

Start the process:

git bisect start
git bisect bad
git bisect good v1.0.0

Git checks out a midpoint commit. You test it and tell Git whether that commit is good or bad.

git bisect good

or:

git bisect bad

Git keeps narrowing the range until it identifies the likely offending commit.

Why It Matters

If a problem appeared somewhere in the last 100 commits, bisect can reduce manual hunting dramatically.

Reflog

git reflog records where HEAD and branch references have pointed over time. It is a lifesaver when you accidentally lose track of commits after reset, rebase, or checkout operations.

Run:

git reflog

You may see entries like:

a1b2c3d HEAD@{0}: reset: moving to HEAD~1
d4e5f6g HEAD@{1}: commit: Add deployment notes

If you hard-reset by mistake, reflog can help you recover:

git reset --hard d4e5f6g

Note: Reflog tracks your local reference movement. It is one of the best recovery tools for “I think I lost my commit” moments.

Submodules Intro

A submodule lets one Git repository include another repository at a specific commit.

Example use cases:

  • sharing a library across projects
  • embedding a documentation site repo inside a larger platform repo
  • keeping a dependency as a separate repository with its own history

Add a submodule:

git submodule add https://github.com/example/shared-lib.git libs/shared-lib

Clone a project with submodules:

git clone --recurse-submodules https://github.com/example/platform.git

Submodules are powerful, but they add complexity because the parent repo tracks a pointer to a specific child repo commit rather than copying its full contents into normal history.

Hooks Intro

Git hooks are scripts that run automatically at certain lifecycle events. They live in .git/hooks for a repository.

Common examples:

  • pre-commit: run formatting or tests before a commit completes
  • commit-msg: validate commit message format
  • pre-push: run checks before pushing

A simple pre-commit hook might run:

npm test

Hooks can improve quality by catching issues early, but local hooks are not always shared automatically unless your team uses a dedicated hook management approach.

Aliases

Aliases let you define short names for longer Git commands.

Create a useful alias for a compact log view:

git config --global alias.lg "log --oneline --graph --decorate --all"

Now run:

git lg

Another popular alias:

git config --global alias.st status

Then:

git st

Aliases reduce typing and make frequent commands easier to remember.

Putting Advanced Git to Work

Here is a practical scenario:

  • a bug appears in production
  • git bisect helps find the bad commit
  • you use git revert or a hotfix commit to fix it
  • you cherry-pick the fix into a release branch
  • a teammate accidentally resets a branch, and git reflog helps recover the lost commit
  • a pre-push hook prevents future broken pushes

These tools are different, but together they make teams more resilient.

When to Reach for These Tools

Use cherry-pick when

  • one commit should move across branches

Use bisect when

  • you know something broke, but not which commit caused it

Use reflog when

  • a commit seems lost after reset, rebase, or checkout

Use submodules when

  • a separate repository must be referenced inside another repo

Use hooks when

  • repetitive checks should run automatically

Use aliases when

  • you want faster daily command usage

What You Should Remember

Advanced Git is about control and recovery. cherry-pick moves specific changes, bisect finds the commit that broke something, and reflog helps recover from history mistakes. Submodules, hooks, and aliases extend Git into larger workflows and better habits.

You do not need these commands every day, but learning them now makes you much more confident when the simple path stops being enough.

Test Your Understanding

Let's see how well you understood the concepts! These exercises will help reinforce what you just learned.

Exercise 1: Backporting one fix

Scenario: A bug fix already exists on main, and you need the same single commit on release/1.2 without merging the whole branch.

Question: Which advanced Git tool from the tutorial is designed for that?

Exercise

Exercise 1: Backporting one fix

Choose the command meant for applying one specific existing commit to another branch.

Exercise 2: Finding the bad commit quickly

Scenario: A regression appeared sometime in the last 100 commits, but nobody knows which one caused it.

Question: Which tool from the lesson is built to narrow that search efficiently?

Exercise

Exercise 2: Finding the bad commit quickly

Pick the advanced Git workflow that uses a binary search through history.

Exercise 3: Recovering after a mistake

Scenario: You ran a hard reset and think you lost a useful commit from yesterday.

Question: Which advanced Git feature from the tutorial gives you the best chance to find and recover it?

Exercise

Exercise 3: Recovering after a mistake

Choose the recovery tool that records where HEAD and branch references pointed locally.

PreviousPrev
Next

Continue Learning

Undoing Changes in Git

Learn how to use restore, reset, revert, and clean safely, and understand the difference between undoing local work and undoing shared history.

18 min·Medium

Git Tagging

Learn how Git tags work, including annotated and lightweight tags, pushing tags, deleting tags, and checking out a tag.

10 min·Easy

GitHub Workflow with Git

Learn a practical GitHub workflow using forks, clones, feature branches, pull requests, code review, and squash and merge.

20 min·Medium

Explore Related Topics

CI

CI/CD Tutorials

Trigger automated pipelines from Git workflows

Li

Linux Tutorials

Use Git effectively on the Linux command line

On This Page

Why Learn Advanced Git?Cherry-PickWhen to Use ItBisectWhy It MattersReflogSubmodules IntroHooks IntroAliasesPutting Advanced Git to WorkWhen to Reach for These ToolsUse `cherry-pick` whenUse `bisect` whenUse `reflog` whenUse submodules whenUse hooks whenUse aliases whenWhat You Should RememberTest Your UnderstandingExercise 1: Backporting one fixExercise 2: Finding the bad commit quicklyExercise 3: Recovering after a mistake