LIBER DE ARTE MERCURII · VOL. I · WHERE ART & CODE MEET AFTER DARK

Git Cheat Sheet

The Velvet Hour · Commands Rooted in Depth & Discipline

An archival illuminated compendium treating version control as an enduring midnight lexicon. Browse every command by category: Actions, Inspect, Utilities, and Undo & Recovery.

4 Categories30 CommandsCryptographic Directed Acyclic Graph

Showing 30 commands

Actions · No. 01

Initgit init

Create a new Git repository in the current folder, or start version control on an existing project.

From Latin initium (“beginning, entrance, fundamental principle”), inire (“to go into”).

The ritual invocation by which an ordinary filing system is endowed with a hidden sanctuary (.git), establishing the Object Database, the Reference Registry (refs/heads), and the architectural configuration parchment.

01Consecrate current working chamber with default primary trunk.
git init
02Initialize a designated repository folio under an explicit canonical branch appellation.
git init -b <initial-branch> <directory-name>
Tune Parameters:
03Found a cloistered custodial depot devoid of a working desk, intended purely for monastic remote exchange.
git init --bare <depot.git>
Tune Parameters:

Actions · No. 02

Clonegit clone

Download a copy of a remote repository (from GitHub, GitLab, Bitbucket) to your computer, including its full history.

From Ancient Greek κλών (klṓn, “twig, slip used for propagation”).

Duplicates not merely the present surface state of a repository, but the entire unbroken ancestral chain of commits, tags, and tree manifests since the first recorded epoch.

01Transcribe the complete historical corpus into an eponymous chamber.
git clone <remote-url>
Tune Parameters:
02Shallow transcript limiting ancestral depth to recent generations.
git clone --depth=<depth> <remote-url>
Tune Parameters:
03Isolate and transcript solely a single designated branch lineage.
git clone --single-branch -b <branch-name> <remote-url>
Tune Parameters:

Inspect · No. 03

Statusgit status

See which files are changed, staged, or untracked, and which branch you are on.

From Latin status (“standing, position, posture, condition of being”).

The diagnostic survey that reveals modifications untracked, amendments staged for immortality, and divergences between the scribe’s immediate folio and the remote beacon.

01Deliver an articulate exposition of all staged, modified, and untracked folios.
git status
02Render a laconic two-column ledger featuring branch synchronization telemetry.
git status -s -b

Utilities · No. 04

Configgit config

Set your Git username and email, default branch name, editor, and aliases, globally or per repository.

From Latin configurare (“to fashion, shape, form symmetrically”).

Maintains three distinct layers of institutional policy: system-wide (/etc/gitconfig), personal scribe level (~/.gitconfig), and local repository charter (.git/config).

01Inscribe the canonical attribution signatures across all future personal codices.
git config --global user.name "<scribe-name>" && git config --global user.email "<email>"
Tune Parameters:
02Enforce cryptographic wax seal signing upon every committed entry.
git config --global commit.gpgSign true

Actions · No. 05

Addgit add

Stage changed files for the next commit: add one file, a folder, or all changes at once.

From Latin addere (“to put to, join, attach, augment”).

Git separates the scribe’s working scratchpad from the permanent historical record via the Index. Invoking add computes the SHA-1/256 hash of the modified content, casts it as an immutable blob in .git/objects, and updates the index register.

01Stage specific folio or directory into the upcoming snapshot index.
git add <pathspec>
Tune Parameters:
02Interactive examination of individual hunks, allowing surgical partial staging.
git add -p <pathspec>
Tune Parameters:
03Stage all additions, modifications, and deletions across the entire sanctum.
git add -A

Actions · No. 06

Commitgit commit

Save your staged changes to history with a commit message. Also used to amend (edit) the last commit.

From Latin committo (“to join together, connect, entrust, perpetrate”).

Creates a tree object reflecting the staged directory structure and a commit object bearing the author attribution, committer signature, timestamp, log message, and pointer to its parent commit.

01Consign staged amendments to eternity with an explanatory marginal inscription.
git commit -m "<message>"
Tune Parameters:
02Absorb staged corrections into the most recent commit without altering its text.
git commit --amend --no-edit
03Affix an undeniable cryptographic seal (GPG/SSH) upon the recorded epoch.
git commit -S -m "<message>"
Tune Parameters:

Actions · No. 07

Restoregit restore

Discard local changes to a file, or unstage a file you added by mistake, without touching commits.

From Latin restaurare (“to rebuild, renew, reinstate, repair”).

Introduced in modern Git dispensations to separate file checkout responsibilities from branch switching rituals, restore cleanly returns parchments to their clean index or HEAD condition.

01Discard uncommitted alterations in the working chamber, reverting to the index.
git restore <pathspec>
Tune Parameters:
02Unstage a parchment from the upcoming commit without discarding its working changes.
git restore --staged <pathspec>
Tune Parameters:

Actions · No. 08

Rmgit rm

Delete a file from the repository and stage the removal, or stop tracking a file but keep it on disk.

From Old French remouvoir, Latin removere (“to move back, remove, take away”).

Registers a deletion event in the index while deleting the physical file from the disk, preparing a commit that formally terminates the file’s tenure in the active lineage.

01Expunge the folio from disk and schedule its deletion in the index.
git rm <pathspec>
Tune Parameters:
02Remove from the versioned index while preserving the physical file on the scribe’s desk.
git rm --cached <pathspec>
Tune Parameters:

Actions · No. 09

Taggit tag

Mark a specific commit with a version label such as v1.0.0, list tags, push tags, or delete a tag.

From Middle English tagge (“a small hanging piece, a label attached to something”).

Unlike a branch, a tag never moves. Lightweight tags are just a name pointing at a commit; annotated tags (-a) are full objects that store the tagger, date, and a message, and can be GPG-signed. Use annotated tags for releases.

01List existing tags, optionally filtered by a glob pattern.
git tag -l "<pattern>"
Tune Parameters:
02Create an annotated release tag on the current commit.
git tag -a <tag-name> -m "<message>"
Tune Parameters:
03Tags are not pushed by default — push one explicitly (or use --tags for all).
git push <remote> <tag-name>
Tune Parameters:
04Delete a local tag (use `git push <remote> --delete <tag-name>` for the remote copy).
git tag -d <tag-name>
Tune Parameters:

Actions · No. 10

Cleangit clean

Remove untracked files and folders from your working directory, with a dry run to preview first.

From Old English clǣne (“free from dirt, pure”).

Removes files Git is not tracking — build output, stray logs, generated files. Because untracked files were never committed, Git has no copy of them: once cleaned, they are gone for good. Always preview with -n first.

01Dry run: show which untracked files and folders would be deleted, without deleting anything.
git clean -n -d
02Delete untracked files and folders (keeps files listed in .gitignore).
git clean -f -d
03Interactive mode: choose file by file what to delete.
git clean -i
04Also delete ignored files (node_modules, .env, build caches) — a full reset to a fresh checkout.
git clean -f -d -x

Inspect · No. 11

Branchgit branch

List, create, rename, or delete branches, including deleting local branches that are already merged.

From Old French branche, Late Latin branca (“paw, footprint, limb of tree”).

In Git, a branch is not a duplicated folder of files; it is merely a 41-byte text file inside .git/refs/heads containing the 40-character hexadecimal SHA of its leading commit.

01Survey all local and cloistered remote branch tributaries with their current SHA tips.
git branch -a -v
02Sprout a new branch bookmark at the current HEAD without stepping onto it.
git branch <new-branch-name>
Tune Parameters:
03Gently dissolve a branch bookmark that has already been merged into an active trunk.
git branch -d <branch-name>
Tune Parameters:

Actions · No. 12

Switchgit switch

Change to another branch, or create a new branch and switch to it in one step.

From Middle Low German swichten (“to calm, pacify, change direction swiftly”).

Replaces the contents of the working chamber and index to reflect the state of the designated branch, redirecting the symbolic ref .git/HEAD.

01Transition the working desk to an existing branch trajectory.
git switch <branch-name>
Tune Parameters:
02Sprout a new branch lineage and simultaneously transport the scribe into it.
git switch -c <new-branch-name>
Tune Parameters:
03Visit an ancient commit directly without mooring HEAD to any branch label.
git switch --detach <commit-hash>
Tune Parameters:

Actions · No. 13

Mergegit merge

Combine another branch into your current branch, and resolve merge conflicts when they happen.

From Latin mergere (“to plunge into, immerse, dip, combine into a unified stream”).

Calculates the Best Common Ancestor of the active and target branches, synthesizes the delta, and unless executed as a fast-forward, fashions an illuminated Merge Commit possessing two distinct parent lineages.

01Unite the specified tributary branch into the currently inhabited trunk.
git merge <tributary-branch>
Tune Parameters:
02Enforce the creation of an explicit merge commit, preserving historical topology.
git merge --no-ff -m "<message>" <tributary-branch>
Tune Parameters:
03Withdraw from a conflicted confluence, restoring pre-merge tranquility.
git merge --abort

Actions · No. 14

Rebasegit rebase

Move your commits on top of another branch for a linear history; squash or edit commits with interactive rebase.

Compound of Latin re- (“again, back”) + basis (“foundation, foot, pedestal”).

Rebase takes commits unique to the current branch, creates temporary diff patches, resets the branch pointer to the new base upstream commit, and replays each patch sequentially, forging entirely new commits with updated parentage.

01Transplant the current branch commits onto the tip of the chosen foundation.
git rebase <new-base-branch>
Tune Parameters:
02Convene an interactive scholastic council to reorder, squash, or reword past commits.
git rebase -i HEAD~<count>
Tune Parameters:
03Resume the chronological replay after manually resolving an intermediate conflict.
git rebase --continue

Actions · No. 15

Checkoutgit checkout

Older command to switch branches, create a branch, view an old commit, or discard file changes.

From check + out, as in borrowing a book from a library.

Before Git 2.23, checkout did two unrelated jobs: moving between branches and overwriting files. Those were split into `git switch` (branches) and `git restore` (files). You will still see checkout everywhere in tutorials, scripts and Stack Overflow answers, so it is worth recognising.

01Switch to an existing branch. Modern equivalent: `git switch <branch>`.
git checkout <branch>
Tune Parameters:
02Create a new branch and switch to it. Modern equivalent: `git switch -c <new-branch>`.
git checkout -b <new-branch>
Tune Parameters:
03Look at the project as it was at an old commit ("detached HEAD"). Create a branch if you want to keep changes made here.
git checkout <commit-hash>
Tune Parameters:
04Discard local changes to a file. Modern equivalent: `git restore <file>`.
git checkout -- <file>
Tune Parameters:

Actions · No. 16

Cherry-Pickgit cherry-pick

Copy a single commit from another branch onto your current branch.

Idiomatic: to select the choicest fruits while leaving the rest upon the orchard branch.

Introduces the changes made by one or more existing commits, generating a fresh commit on the currently active branch with an independent hash and timestamp.

01Pluck a specific commit from a parallel timeline and graft its essence onto HEAD.
git cherry-pick <commit-hash>
Tune Parameters:
02Apply the patch delta to the staging index without generating a new commit node.
git cherry-pick -n <commit-hash>
Tune Parameters:

Actions · No. 17

Revertgit revert

Undo a commit safely by creating a new commit that reverses it, without rewriting shared history.

From Latin revertere (“to turn back, come back, return”).

The honorable and safe path of undoing history: rather than expunging past blunders from the ledger, revert records an explicit corrective amendment, preserving the integrity of published public records.

01Fabricate an inverse commit negating the effects of the targeted past epoch.
git revert <commit-hash>
Tune Parameters:
02Revert a complex merge commit, specifying which parent lineage shall be retained as truth.
git revert -m 1 <merge-commit-hash>
Tune Parameters:

Undo & Recovery · No. 18

Resetgit reset

Undo the last commit or move a branch back to an earlier commit, keeping or discarding your changes (soft, mixed, hard).

From Middle English resetten, French recépter (“to receive back, set again”).

Possesses three ascending degrees of severity: --soft (moves HEAD only), --mixed (moves HEAD and resets the index), and --hard (moves HEAD, resets index, and obliterates working desk modifications).

01Rewind the branch pointer while retaining all alterations neatly staged in the index.
git reset --soft HEAD~<count>
Tune Parameters:
02Rewind the branch and unstage the index, leaving changes untouched on disk.
git reset --mixed HEAD~<count>
Tune Parameters:
03Total temporal regression: annihilates all working desk and index work back to target commit.
git reset --hard <target-commit>
Tune Parameters:

Inspect · No. 19

Loggit log

View commit history: one-line log, branch graph, filter by author or date, or see the history of a file.

From Old Norse lág (“felled tree trunk, ship’s logbook recording nautical progress”).

Traverses the directed acyclic graph (DAG) backward from the current HEAD node, deciphering commit messages, author signatures, dates, and topological connections.

01Render the complete monastic lineage as an ASCII genealogical tapestry.
git log --graph --oneline --decorate --all
02Examine detailed line-by-line textual evolution for a designated parchment.
git log -p -<count> <pathspec>
Tune Parameters:
03Audit the historical output of a specific scribe across a defined temporal window.
git log --author="<scribe-name>" --since="<timeframe>"
Tune Parameters:

Utilities · No. 20

Diffgit diff

Show what changed between your working files, staged changes, commits, or branches.

From Latin differre (“to carry apart, put off, defer, differ, disagree”).

Calculates the minimal edit distance (using Myers or Histogram algorithms) between two distinct states of the repository parchment, displaying additions in ink and deletions in vermilion.

01Inspect variations between the uncommitted working desk and the staged index.
git diff
02Inspect variations between the staged index and the latest immutable commit (HEAD).
git diff --staged
03Collate the net difference between two independent historical branch tips.
git diff <branch-alpha>..<branch-beta>
Tune Parameters:

Inspect · No. 21

Blamegit blame

See who last changed each line of a file, and in which commit.

From Old French blasmer, Greek βλασφημεῖν (blasphēmeîn, “to speak ill of, blaspheme”).

While colloquial developers refer to it as "blame", historical purists often evoke its synonym `git annotate`. It serves as the ultimate provenance ledger for intellectual attribution.

01Inscribe the author, date, and commit SHA alongside every verse in the parchment.
git blame <pathspec>
Tune Parameters:
02Restrict scribal provenance inquiry to a specific line range.
git blame -L <start>,<end> <pathspec>
Tune Parameters:

Inspect · No. 22

Showgit show

Show the details and changes of a single commit or tag, or view a file as it was in an older commit.

From Old English scēawian (“to look at, behold, examine”).

Where `git log` lists many commits, `git show` zooms in on one object. With no arguments it shows the latest commit. With `<commit>:<path>` it prints the full contents of a file at that commit, without checking anything out.

01Show the most recent commit: author, date, message and full diff.
git show
02Show a specific commit (or tag) and its changes.
git show <commit-hash>
Tune Parameters:
03Summarise which files a commit touched, without the full diff.
git show --stat <commit-hash>
Tune Parameters:
04Print a file exactly as it was at a given commit or branch.
git show <commit>:<path>
Tune Parameters:

Utilities · No. 23

Bisectgit bisect

Find which commit introduced a bug by binary-searching through history, manually or with an automated test.

From Latin bi- (“two”) + secare (“to cut”): to cut in two.

You mark one commit as good (bug absent) and one as bad (bug present). Git checks out the midpoint; you test and answer good or bad; Git halves the range again. Even across 1,000 commits it takes only about 10 steps to pinpoint the culprit.

01Begin a bisect session between a broken commit and a known-working one.
git bisect start <bad> <good>
Tune Parameters:
02After testing the checked-out commit, tell Git whether the bug is present.
git bisect good # or: git bisect bad
03Automate it: Git runs your test at each step (exit 0 = good, non-zero = bad).
git bisect run <test-command>
Tune Parameters:
04End the session and return to the branch you started on.
git bisect reset

Actions · No. 24

Fetchgit fetch

Download new commits and branches from the remote without changing your local files.

From Old English feccan (“to reach, gain, seek, take, retrieve”).

The prudent and scholarly way to inspect distant developments: fetches all new commit objects from a designated remote harbor and updates remote-tracking references (e.g. origin/main) safely in the background.

01Download all fresh remote scrolls and prune references extinguished by distant peers.
git fetch --all --prune
02Harvest objects belonging to an isolated remote branch without touching local working tree.
git fetch origin <branch-name>
Tune Parameters:

Actions · No. 25

Pullgit pull

Update your current branch with changes from the remote: fetch, then merge or rebase.

From Old English pullian (“to draw with force, pluck, tug”).

Brings your active local branch into parity with its upstream tracking counterpart by fetching remote updates and immediately integrating them into your current working lineage.

01Fetch upstream scrolls and merge them into the active working branch.
git pull
02Fetch and replay local unpushed commits linearly atop the fresh remote foundation.
git pull --rebase

Actions · No. 26

Pushgit push

Upload your local commits to the remote repository, set the upstream branch, or force push safely.

From Old French pousser, Latin pulsare (“to push, strike, beat, propel forward”).

Uploads newly consecrated commit objects, trees, and blobs to the remote depository and requests that the remote reference pointer be advanced to your new local SHA.

01Publish a maiden branch and establish persistent upstream tracking relationship.
git push -u origin <branch-name>
Tune Parameters:
02Publish rewritten history safely, aborting if distant peers have published unexpected work.
git push --force-with-lease
03Extinguish an obsolete branch in the distant monastery.
git push origin --delete <old-remote-branch>
Tune Parameters:

Utilities · No. 27

Remotegit remote

Show, add, rename, or remove remote repositories such as origin and upstream, and change a remote URL.

From Latin remotus (“distant, far off”), past participle of removere.

A remote is just a short name for a URL. `git clone` creates one called origin automatically. Forks typically add a second remote called upstream pointing at the original project, so you can pull its changes into your fork.

01List all remotes with their fetch and push URLs.
git remote -v
02Connect a new remote, e.g. upstream for a fork.
git remote add <name> <url>
Tune Parameters:
03Change a remote URL, e.g. switching from HTTPS to SSH or after a repo move.
git remote set-url <name> <new-url>
Tune Parameters:
04Disconnect a remote and delete its remote-tracking branches locally.
git remote remove <name>
Tune Parameters:

Undo & Recovery · No. 28

Refloggit reflog

Recover lost commits or deleted branches, and undo a bad reset or rebase, using the log of where HEAD has been.

Portmanteau of Reference + Log: the chronicle of reference movements.

When all seems lost—after a catastrophic `reset --hard`, a botched rebase, or an accidental branch deletion—the Reflog remains your immortal salvation. It records every moment HEAD changed location locally, even if commits were severed from branch tips.

01Disclose the subterranean ledger of recent HEAD movements and operations.
git reflog
02Resurrect an orphaned commit discovered in the reflog into an active branch.
git branch <salvaged-branch> <reflog-sha>
Tune Parameters:
03Undo the immediately preceding catastrophic action, stepping backward in local time.
git reset --hard HEAD@{1}

Utilities · No. 29

Stashgit stash

Temporarily save uncommitted changes so you can switch branches, then bring them back later.

Colloquial English stash (“to store something safely in a concealed repository”).

Captures the unfinished drafts from your working desk and index, records them as special commit objects under refs/stash, and restores your working tree to pristine HEAD tranquility.

01Conceal unfinished drafts with an explanatory manuscript note.
git stash push -m "<annotation>"
Tune Parameters:
02Retrieve the most recent concealed draft and remove it from the stash vault.
git stash pop
03Survey all stored drafts nestled within the subterranean stash vault.
git stash list

Utilities · No. 30

Fsckgit fsck

Check the repository for corruption, and find dangling or lost commits that can still be recovered.

File System Consistency Check: UNIX ritual of forensic integrity verification.

Audits every blob, tree, commit, and tag object in .git/objects, detecting corrupted checksums, broken pointers, and locating dangling objects unlinked to any named branch.

01Audit depository integrity and recover dangling orphaned objects into .git/lost-found.
git fsck --lost-found
02Identify all severed commit and blob nodes floating without branch moorings.
git fsck --unreachable