Tutorial Git DevOps Developer Tools Cheat Sheet

Free Git Advanced Patterns Cheat Sheet Online — Interactive Reference for Developers

· 20 min read

Every developer knows the basic Git commands: git add, git commit, git push, git pull. These are the verbs of version control, and they are sufficient for straightforward workflows. But real software development is rarely straightforward. You will need to rewrite history to clean up a messy feature branch before code review. You will need to find the exact commit that introduced a regression in a codebase with thousands of changes. You will need to recover a branch you accidentally deleted with git branch -D. You will need to cherry-pick a critical bug fix across three release branches while preserving signatures. These are not edge cases. They are the daily reality of working with Git at scale. That is why we built the free interactive Git Advanced Patterns Cheat Sheet.

Our cheat sheet covers the commands and workflows that separate Git beginners from Git power users. It targets the patterns developers actually search for: git rebase interactive for history rewriting, git cherry-pick for selective commit application, git bisect for binary-search debugging, git reflog for disaster recovery, git stash and git worktree for context switching, git submodule and git subtree for multi-repository workflows, git hooks and git aliases for automation, git merge strategies for conflict resolution, and git signing for cryptographic verification. Every entry includes a realistic command example, a concise explanation, and one-click copy. The design follows The Time Cartographer's Archive aesthetic — deep burgundy-black backgrounds, aged parchment cards, gold and silver ink accents, and a branching constellation animation that visualizes Git history as a living map.

Skip ahead: If you want to explore the tool while reading, open the Git Advanced Patterns Cheat Sheet in another tab. Use it to test the commands in this article in real time.

History Rewriting: Cleaning Up Before You Share

Git's most powerful and dangerous feature is its ability to rewrite history. Once you push commits to a shared remote, rewriting history becomes risky because it changes commit hashes and can orphan your collaborators' work. But before pushing — on your local feature branch — rewriting history is not just acceptable, it is a best practice. A clean, linear, well-explained commit history makes code review faster, git bisect more effective, and git blame more useful.

Amending the Last Commit

The simplest form of history rewriting is amending the most recent commit. If you forgot to stage a file, made a typo in the commit message, or need to add a quick fix, git commit --amend replaces the last commit with a new one containing the staged changes.

git commit --amend -m "Fix navigation bug on mobile viewports"

Use --no-edit to keep the existing message while adding new staged files:

git add forgotten-file.js
git commit --amend --no-edit

Remember: amending changes the commit hash. If you have already pushed the original commit, you will need to force-push the amended version.

Interactive Rebase: The Swiss Army Knife of History

git rebase interactive is the single most powerful tool for cleaning up commit history. It opens an editor showing the last N commits and lets you squash, reorder, edit, or drop them.

git rebase -i HEAD~5

The editor presents a list of commands: pick (keep), reword (edit message), squash (merge into previous), fixup (merge and discard message), edit (pause to amend), drop (remove), and exec (run a shell command). Reordering the lines reorders the commits. This one command can transform a chaotic feature branch into a clean, logical sequence of focused commits.

For automatic squashing without manual editing, create fixup commits and rebase with --autosquash:

git commit --fixup=:/"feat: add auth"
git rebase -i --autosquash main

Transplanting Branches with Rebase --onto

When a feature branch was created from the wrong base, or when the base branch has moved, git rebase --onto transplants the commits onto a new base without replaying the entire history.

git rebase --onto new-base old-base feature-branch

This replays commits from old-base to feature-branch onto new-base. It is the cleanest way to move a feature branch when its parent has been rebased or squashed.

Rewriting History at Scale

For repository-wide history rewriting — removing secrets, fixing author emails, or splitting directories into separate repos — git filter-branch was the legacy tool. It is now deprecated in favor of git filter-repo, which is faster, safer, and produces cleaner results.

# Remove a file from all history
git filter-repo --path secret.txt --invert-paths

# Change author email across all commits
git filter-repo --mailmap .mailmap

Warning: these commands rewrite every commit in history. They should only be used on private branches or with full team coordination.

Branching and Merging Strategies

Branching is cheap in Git, but merging strategy matters. A fast-forward merge produces a linear history. A no-fast-forward merge creates a merge commit that preserves the feature branch context. Squash merging collapses an entire feature into a single commit. Rebase merging replays feature commits onto the target branch for a linear history. The right choice depends on your team's workflow and release process.

Merge Strategies and Options

git merge --no-ff always creates a merge commit, even when a fast-forward is possible. This preserves the feature branch boundary in history, which is useful for tracking which commits belonged to which feature.

git merge --no-ff feature-auth

git merge --squash stages all changes from the feature branch as a single unstaged change. You then commit it with a unified message. This is common in trunk-based workflows where feature branch granularity is not preserved.

When conflicts arise, -X ours or -X theirs automatically resolves conflicts by favoring one side:

git merge -X theirs feature-branch

Safe Branch Operations

Modern Git provides git switch for branch operations, which is safer than git checkout because it refuses to overwrite files. Switch to the previous branch with a single hyphen:

git switch -

Create a tracking branch in one command:

git switch -c feature-x origin/feature-x

Debugging and Inspection

When something breaks, Git provides powerful tools for understanding what changed, when, and why. git blame, git bisect, and advanced git log are the debugging trifecta.

Git Blame: Annotating Every Line

git blame shows the last commit that modified each line of a file. Use -L to limit the range and -C to detect lines moved from other files:

git blame -L 50,100 src/auth.js
git blame -C -C src/utils.js

Git Bisect: Binary Search for Bugs

git bisect finds the exact commit that introduced a bug by binary searching through history. You mark a known bad commit and a known good commit, then Git guides you through testing midpoints.

git bisect start
git bisect bad HEAD
git bisect good v1.2.0
# Test the checkout, then mark:
git bisect good   # or bad
git bisect reset

For automated bisection, provide a test script that exits 0 for good and 1-127 for bad:

git bisect run ./test.sh

Advanced Git Log

git log is far more powerful than most developers realize. Combine flags to produce exactly the view you need:

git log --oneline --graph --all --decorate   # visual graph
git log --grep="fix" --author="Alice" -S"bug"   # search commits
git log -p -- src/app.js                      # patch for a file
git log --stat                                # summary stats

Advanced Git Diff

Triple-dot diff shows changes since a branch diverged:

git diff main...feature

Show only changed filenames:

git diff --name-only main...feature

View a file as it existed in a specific commit:

git show abc1234:src/app.js

Stashing and Worktrees

Context switching is inevitable. You are halfway through a feature when a critical production bug requires immediate attention. Stashing and worktrees are the two primary tools for preserving work-in-progress without committing broken code.

Git Stash: Save Work Without Committing

git stash saves your working directory and index, then reverts to a clean state. Modern Git supports named stashes, partial stashing, and including untracked files:

git stash push -m "WIP: refactor auth" -p          # interactive hunks
git stash push --include-untracked -m "with deps"  # include untracked
git stash show -p stash@{1}                        # view as patch
git stash branch bugfix stash@{1}                  # new branch from stash

Git Worktree: Multiple Working Directories

git worktree creates additional working directories linked to the same repository. This eliminates the stash-pop cycle when switching branches. Each worktree has its own checkout but shares the object database.

git worktree add ../project-hotfix hotfix
git worktree list
git worktree remove ../project-hotfix

Worktrees are ideal for long-running branches, code reviews, or maintaining multiple release lines simultaneously.

Sparse Checkout: Partial Working Trees

For monorepos, git sparse-checkout limits the working tree to specific directories, dramatically reducing checkout time and disk usage:

git sparse-checkout init --cone
git sparse-checkout set packages/frontend packages/shared

Collaboration and Patch Management

Not all collaboration happens through pull requests. Patches, notes, and selective commit application are essential for distributed workflows, email-based code review, and cross-repository maintenance.

Cherry-Pick: Selective Commit Application

git cherry-pick applies a single commit from one branch to another. Use -n to apply without committing, and -x to include the original commit reference:

git cherry-pick -x abc1234
git cherry-pick -n abc1234

For merge commits, specify the mainline parent:

git cherry-pick -m 1 abc1234

Patch Files and Mailboxes

git format-patch creates patch files from commits in mailbox format. git am applies them. This is the foundation of email-based workflows and Linux kernel development:

git format-patch -3 HEAD~3
git am 0001-fix.patch
git format-patch --stdout main..feature > feature.patch

Git Notes: Annotating Commits

git notes attaches additional metadata to commits without changing the commit hash. Notes are stored separately and can be pushed to remotes:

git notes add -m "Reviewed by Alice" abc1234
git notes show abc1234
git push origin refs/notes/*

Submodules, Subtrees, and Bundles

Multi-repository workflows are complex. Submodules link external repositories as subdirectories. Subtrees merge external repositories into your tree. Bundles create portable repository snapshots.

Git Submodules

git submodule add https://github.com/user/lib.git vendor/lib
git submodule update --init --recursive
git submodule foreach 'git pull origin main'

Git Subtrees

Subtrees are simpler than submodules for vendoring because collaborators do not need to run submodule commands:

git subtree add --prefix=vendor/lib librepo main --squash
git subtree pull --prefix=vendor/lib librepo main --squash

Git Bundles

Bundles are useful for offline transfer or backup:

git bundle create repo.bundle HEAD~5..HEAD
git bundle verify repo.bundle
git clone repo.bundle

Hooks and Automation

Git hooks are scripts that run automatically at specific points in the Git lifecycle. They live in .git/hooks and can enforce standards, run tests, and automate workflows.

Common Hooks

pre-commit runs before a commit is created. It is the ideal place for linting and formatting:

#!/bin/sh
# .git/hooks/pre-commit
npm run lint
npm run test:unit

pre-push runs before pushing to a remote. Use it for integration tests:

#!/bin/sh
npm run test:integration

prepare-commit-msg auto-generates commit messages from branch names or ticket numbers.

Modern Hook Management

Husky and lint-staged provide modern hook management without editing .git/hooks directly:

# .husky/pre-commit
npx lint-staged

# package.json
"lint-staged": {
  "*.js": ["eslint --fix", "git add"]
}

Git Aliases

Aliases reduce typing for common compound commands:

git config --global alias.st status
git config --global alias.lg "log --oneline --graph --decorate --all"
git config --global alias.undo "reset --soft HEAD~1"
git config --global alias.amend "commit --amend --no-edit"

Tags and Signing

Tags mark specific points in history, typically releases. Annotated tags store metadata. Signed tags provide cryptographic verification.

Creating and Managing Tags

git tag -a v1.0.0 -m "Initial release"
git tag -s v1.0.0 -m "Signed release"
git tag -v v1.0.0              # verify signature
git push origin v1.0.0         # push specific tag
git push origin --tags         # push all tags

GPG Signing Commits

Enable automatic commit signing and set your default key:

git config --global commit.gpgsign true
git config --global user.signingkey KEYID

Related Tools

Frequently Asked Questions

Is this Git Advanced Patterns Cheat Sheet free?

Yes. The tool is completely free with no limits, no registration, and no advertisements.

How many entries are included?

The cheat sheet contains over 65 entries across 8 categories, covering the advanced Git workflows that professional developers use daily.

Can I search for specific commands?

Yes. The search bar filters entries in real time by command name, description, or example content.

Is my data safe?

Yes. The cheat sheet is one hundred percent client-side. No commands or usage data are sent to a server.

Does this replace the official Git documentation?

No. This cheat sheet is a quick reference for advanced patterns. For deep understanding of Git internals, plumbing commands, and edge cases, consult the official git-scm.com documentation.

Conclusion

Git is simple to learn and infinitely deep to master. The commands in this article — git rebase interactive, git cherry-pick, git bisect, git reflog, git worktree, git submodule, git hooks, and the rest — are the tools that separate casual users from power users. Our free interactive Git Advanced Patterns Cheat Sheet puts all of them at your fingertips. With category filtering, real-time search, one-click copy, and a distinctive archival cartography aesthetic, it is the fastest way to find the advanced Git command you need without breaking your flow. Bookmark it, share it with your team, and keep shipping.

Found this useful? Check out our free developer tools or browse more articles.