Git
About this knowledge base
This directory is organized from the official Git cheat sheet and adds local installation guidance, usage scenarios for each command category, common risks, and more modern alternatives. Commands remain in English; the explanations are localized.
Git is a distributed version-control system. Alongside the existing command tutorials, this knowledge base provides an AI Agent Engineer learning route from zero: first build a mental model of snapshots, objects, and references; then understand the working tree, staging area, and HEAD; then learn branches, diffs, recovery, and remote collaboration; finally complete a project in an isolated experimental repository. Do not run cleanup, hard resets, history rewrites, or force pushes in a real working tree until you understand their impact.
Sources
Original page: Git Cheat Sheet; PDF: cheat-sheet.pdf; Windows installation page: Installing Git.
Command placeholders
<path>,<commit>,<branch>, and<url>in headings or inline commands mean “replace this with a real value”; do not type the angle brackets literally into PowerShell. To prevent accidental copy/paste, this course’s PowerShell blocks use parseable examples such asREADME.md,HEAD~1, andfeature/demo. A path argument prefixed with--makes the end of options explicit.
Where this course fits in the overall route
This course is in the Engineering Foundations stage. It builds on Markdown and command-line basics, providing reviewable and recoverable change history for later Python projects, Agent tools, evaluation assets, and production configuration. Git tracks versions only; it does not replace tests, artifact storage, secret management, or deployment approval.
Learning objectives
- Explain the relationship among a working tree, staging area, commits, and branches.
- Inspect status, diffs, untracked files, and sensitive-information risk before a commit.
- Use branches to isolate Agent code, prompts, configuration, and evaluation changes.
- Choose among
restore,revert,reset, andreflogrecovery approaches. - Synchronize remote repositories safely and understand the risk of rewriting shared history.
- Complete an isolated-repository practice from initialization through conflict resolution, rollback, and review.
Prerequisites
The primary environment is Windows 11 with PowerShell 7. You only need to know how to change directories and edit text. It is recommended to complete Markdown first; installation and identity configuration begin in lesson 1.
Recommended order
- 01 Install Git Locally — installation, verification, and minimum identity configuration.
- 02 Getting Started and Creating a Repository — recognize repositories and initialize or clone safely.
- 02A Git State Model and Commit Graph — build a model of snapshots, objects, index,
HEAD, references, and commit graph. - 03 Staging Area and File Operations — choose precisely what belongs in a commit.
- 04 Commits and Pre-Commit Checks — build reviewable commit habits.
- 05 Switching and Managing Branches — use references to isolate lines of task work.
- 05A Branch Merging and Conflict Resolution — understand fast-forward, three-way merge, conflict resolution, and safe abort.
- 06 Diffing and Commit References — use evidence to understand actual changes.
- 07 Undoing and Cleaning Up — determine state before selecting a recovery command.
- 08 History Rewriting and Failure Recovery — use only after understanding shared history.
- 09 History Tracing and Code Archaeology — locate the commit that introduced a line or behavior.
- 10 Remote Repository Synchronization — understand fetch, pull, push, and conflict.
- 10A Remote Collaboration and Offline Two-Clone Lab — distinguish remote references and simulate two collaborators offline.
- 11 Git Configuration and Key Files — manage configuration, ignores, and key repository files.
- 12 Version-Control Practice and Self-Check — finish the integrated task in an isolated experimental repository.
Quick entry points
- Git is not installed locally: Install Git Locally.
- Creating or obtaining a repository: Getting Started and Creating a Repository.
- Commands are all blending together: Git State Model and Commit Graph.
- Preparing a commit: Staging Area and File Operations, then Commits and Pre-Commit Checks.
- Branch work: Switching and Managing Branches.
- Merge and conflict: Branch Merging and Conflict Resolution.
- Inspecting changes: Diffing and Commit References.
- Undo or cleanup: Undoing and Cleaning Up for high-risk-command guidance.
- Altering commit history: History Rewriting and Failure Recovery, only after understanding the impact.
- Tracking history and finding responsible lines: History Tracing and Code Archaeology.
- Syncing a remote: Remote Repository Synchronization.
- Practicing remote collaboration without an account: Remote Collaboration and Offline Two-Clone Lab.
- User name, aliases, and ignored files: Git Configuration and Key Files.
Hands-on work and project entry
See Version-Control Practice and Self-Check for the integrated task. All destructive exercises belong in a newly created isolated experimental repository. Preserve evidence with git status, git diff, and git log before executing a recovery command.
Mastery checklist
- Can draw the working-tree → staging-area → commit flow and verify it with commands.
- Before every commit, inspect staged and unstaged diffs, untracked files, and credential risk.
- Can create a branch, create and resolve a text conflict, and explain the resulting content.
- Can distinguish undoing uncommitted changes, creating an inverse commit, and moving a branch pointer.
- Can recover a locally unreachable commit with
reflog. - Do not casually rewrite shared branches; when force pushing is necessary, first understand and prefer
--force-with-lease. - Can explain why
.gitignorecannot protect credentials that have already entered history.
Relationship to other knowledge bases
| Next knowledge base | Connection |
|---|---|
| Markdown | Documentation and prompts are textual assets with readable diffs. |
| Python Fundamentals | Source code, tests, and dependency declarations should form reproducible commits. |
| Linux Commands | Server-side Git operations rely on reliable command-line and path judgment. |
| MLOps, LLMOps | Git records code version; data, models, prompts, evaluation, and deployment need additional tracking. |
| Agent Skills, MCP | Tool contracts and configuration changes should be reviewable and reversible. |
Primary references
Checked 2026-07-14. The current official stable-documentation baseline was Git 2.55.0; this machine’s available syntax was checked under Windows 11, PowerShell 7, and git version 2.54.0.windows.1. They are recorded separately: a local version is not a global latest version. Options evolve by Git version; before execution, use a focused command such as git help status to consult local documentation.