G
GuideDevOps
Lesson 16 of 18

Advanced Git (Bisect, Blame, Submodules)

Part of the Git & Version Control tutorial series.

Git provides several powerful tools for deep analysis and managing complex project structures. These advanced features are essential for large teams and maintaining legacy codebases.

1. Git Bisect: Find the Bug

git bisect uses a binary search algorithm to find which specific commit introduced a bug. It's like "Who Wants to Be a Millionaire" for your code.

The Workflow

  1. Start with a "bad" commit (current state).
  2. Find a "good" commit (some time in the past where the bug didn't exist).
  3. Git picks the middle commit and asks you to test it.

Action:

git bisect start
git bisect bad                 # Current version is broken
git bisect good v1.0           # Version 1.0 was working

Result:

Bisecting: 675 commits left to test after this (roughly 9 steps)
[f23d45e] Fix login validation logic

Action:

# Test the code... if it's broken:
git bisect bad
# ... repeat until Git finds the commit.

Final Result:

f23d45e6789... is the first bad commit

2. Git Blame: Find the Author

git blame shows you exactly who last modified each line of a file. It's the ultimate tool for accountability and understanding why a line was changed.

Action:

git blame src/app.js

Result:

a1b2c3d4 (John Doe 2026-03-15 14:00:00) 10: const API_URL = "http://localhost:8080";
f5e6d7c8 (Jane Smith 2026-04-01 09:30:00) 11: console.log("Starting app...");

3. Git Submodules: Manage Dependencies

Submodules allow you to keep another Git repository as a subdirectory of your own. This is great for sharing common libraries across multiple projects.

Add a Submodule

Action:

git submodule add https://github.com/org/common-lib.git libs/common

Result:

Cloning into 'libs/common'...
remote: Counting objects: 11, done.
...

Cloning a Repo with Submodules

By default, Git doesn't download submodules when you clone.

Action:

git clone --recursive https://github.com/my-org/my-project.git

4. Git Filter-repo (The "Clean" Tool)

In DevOps, you sometimes accidentally commit a huge binary file or a secret key. git filter-repo (replaces the older filter-branch) allows you to scrub it from the entire history.

Action:

git filter-repo --path my-secret.key --invert-paths

Summary: Advanced Git Toolbox

ToolPurpose
bisectDebugging (finding the "bad" commit)
blameAnalysis (who changed this line?)
submoduleStructure (embedding other repos)
reflogRecovery (find "lost" commits)
filter-repoMaintenance (rewriting history)