Rzemiosło · The Craft
What is The CraftLevelsGet startedChapters Search Download PLEN
Level 2 · Technical ~5 min read

In one sentence: Git history is the project’s memory, almost any mistake can be undone, and a deploy is a separate, deliberate decision — with a tag.

This chapter in plain terms

A chapter about Git and publishing changes “live” — this is where a mistake costs the most. Four topics: history, undoing mistakes, parallel work and the Deploy — Releasing a new version of the app “live”, where real people use it. It’s the moment a change reaches real people — which is why it happens only on an explicit “deploy”. more in the glossary → policy.

Git is a time machine and a shared table. Before you write something, check the history for whether someone already did it (git log, git blame). Keep git status clean: one topic per Commit — A saved, labelled point in the project’s history — a confirmation of a specific batch of changes. Small, described commits make a history you can return to any working state from. more in the glossary →, no junk — and never sweep unfinished work you didn’t write (say, another Claude session’s) into your own commit.

Parallel work: one task, one short Branch — A separate working version of the project where you change something on the side, without touching what already works. On a branch you experiment safely; only what’s been checked reaches the main version. more in the glossary →. Even “solo” you work in several Claude sessions at once — treat each like a separate collaborator. Every task gets an Issue — A task or bug recorded in a tracker (e.g. GitHub Issues), with a description and acceptance criteria. That’s where the “why” of a change lives — not in someone’s head or a chat that will disappear. more in the glossary → and a short branch that lives hours or days, not weeks. Before Merge — Combining the changes from one branch into another. A merge brings in every commit from the source branch — other people’s too — so first you check what exactly comes in. more in the glossary → into the branch you deploy from, look at the Diff — A list of the differences between two versions: what was added and removed, line by line. Reviewing the diff before merging is the last chance to see what’s really going to production. more in the glossary →: a merge brings in every commit from the source, other people’s work included.

Publishing live (deploy) is a separate, deliberate decision. Saving and pushing code isn’t a deploy yet. A real deployment happens only on your explicit “deploy” — never automatically, “since it’s ready”. Every deploy gets a tag and a short plain-language note: what the user gained. (Rehearsing a risky release now has its own chapter → 18, and so does Database swap — Replacing the whole production database with a new version, carrying over user accounts and data. The hardest operation in The Craft — it has its own runbook and needs explicit consent. more in the glossary → the database while keeping accounts → 19.)

Example of a trap: the server deploys the version from the Repository (repo) — A store of the whole project’s code together with its full history of changes — who changed what and when. The repo is the project’s memory: code, documentation and change history in one place. more in the glossary → (origin), not from your laptop. If you forget Push / pull — Push sends your commits to the remote repository; pull fetches changes from there into your copy. A push is an “outward” action — in The Craft it needs explicit consent, like a deploy. more in the glossary →, the server pulls the older version and the “latest changes” simply aren’t there — even though everything looks fine to you. So before a deploy: first git push, then deploy.

Almost nothing in Git is irreversible — on one condition: commit early. A commit is free and private (until you push), and Git remembers every position of a branch for ~90 days. A deleted branch, a “lost” commit, a bad merge — you get back via Reflog — Git’s log of every position your copy has been at — even after a branch was “lost”. Almost every “I lost my work” ends here — it’s the undo button for the whole repository. more in the glossary → (the whole repo’s undo button: find the moment before the mistake, put a branch on it). The only thing that truly vanishes is uncommitted work — and only three commands destroy it (git reset --hard, git restore ., git clean -fd). Commit before an experiment and none of them can hurt you.

Read more: what is Git · branches in Git · git reflog — recovery.

05 — Git and deployments

Commandments II, VI, VIII, IX. Git is the project’s memory and the undo button for everything else; the Deploy — Releasing a new version of the app “live”, where real people use it. It’s the moment a change reaches real people — which is why it happens only on an explicit “deploy”. more in the glossary → policy is where a mistake costs the most. Rehearsal on Preprod (staging) — A faithful copy of production with no real users, where you rehearse a deploy. A migration that fails on preprod is an ordinary Tuesday; in production it’s an incident. more in the glossary → → 18; Environment (dev / prod) — Separate places where the app runs: “dev” for safe tests, “prod” for real users. Dev is a playground, prod is where real users are — the rules for each are completely different. more in the glossary → Database swap — Replacing the whole production database with a new version, carrying over user accounts and data. The hardest operation in The Craft — it has its own runbook and needs explicit consent. more in the glossary → → 19.

Git habits

  1. Search the history before you implement:
    git log -S"symbol" --oneline     # where a symbol/flag/column was born
    git log -G"regex" --oneline      # commits whose diff matches
    git log --grep="word" --oneline  # commit messages
    git blame <file> -L a,b          # who/when/why
  2. Keep git status clean. One topic per Commit — A saved, labelled point in the project’s history — a confirmation of a specific batch of changes. Small, described commits make a history you can return to any working state from. more in the glossary →. Junk (.bak, temp files, stray databases) goes to .gitignore early (# comments on their own line). A file shown as changed with an empty git diff HEAD is CRLF / LF (line endings) — Two ways of storing the end of a line in a file: Windows uses CRLF, Linux and macOS use LF. The difference makes git show “changed” files that nobody actually changed. more in the glossary → noise, not work — don’t commit it.
  3. Orphans: uncommitted work you didn’t write (another session’s) is never swept into your commit or deploy without confirmation — ask whether it’s finished work or an experiment.
  4. Commit messages in English, what + why, refs #N / fixes #N.

Undo: you probably didn’t lose it

Committed work is recoverable; git remembers every position a Branch — A separate working version of the project where you change something on the side, without touching what already works. On a branch you experiment safely; only what’s been checked reaches the main version. more in the glossary → held (~90 days). Commit early — a commit is free, private until Push / pull — Push sends your commits to the remote repository; pull fetches changes from there into your copy. A push is an “outward” action — in The Craft it needs explicit consent, like a deploy. more in the glossary →, and is your save point.

SituationWay back
Wrecked a file, not committedgit restore <file>
Undo the last commit, keep the workgit reset --soft HEAD~1
Committed on the wrong branchgit branch <right> here, then git reset --hard HEAD~1 on the wrong one
Deleted a branch / “lost” commitsReflog — Git’s log of every position your copy has been at — even after a branch was “lost”. Almost every “I lost my work” ends here — it’s the undo button for the whole repository. more in the glossary → → find the hash → git branch <name> <hash>
A Merge — Combining the changes from one branch into another. A merge brings in every commit from the source branch — other people’s too — so first you check what exactly comes in. more in the glossary → went wrong (not pushed)git reset --hard ORIG_HEAD
Need a file as it wasgit show <commit>:<path> · git restore --source=<commit> -- <path>

Only three commands destroy work — and only uncommitted work: git reset --hard, git restore . / git checkout ., git clean -fd. Git has no Dry-run — A “dry” run — the script shows what it WOULD do but changes nothing. You see the effects before executing; a data change happens only after deliberate confirmation. more in the glossary → for them: committing first is the dry-run (→ IV).

Parallel work: issues and short branches

“Solo” is still multi-writer: one developer routinely runs several Claude sessions on one Repository (repo) — A store of the whole project’s code together with its full history of changes — who changed what and when. The repo is the project’s memory: code, documentation and change history in one place. more in the glossary →. The “other party” is usually another session — read “teammate” as “the other session”.

  1. One task = one Issue — A task or bug recorded in a tracker (e.g. GitHub Issues), with a description and acceptance criteria. That’s where the “why” of a change lives — not in someone’s head or a chat that will disappear. more in the glossary →: title = outcome, body = context + acceptance criteria. The issue number ties branch, commits and PR (pull request) — A request to merge a branch into the main version, with a description of the changes and room for review. A small PR can be reviewed properly in fifteen minutes; a huge one goes through “on trust”. more in the glossary → together; the PR/merge closes it, not a work-branch commit.
  2. Short branches (feat/NN-cart, fix/NN-login) living hours–days; small PRs; merge, delete, sync with main often.
  3. Diff — A list of the differences between two versions: what was added and removed, line by line. Reviewing the diff before merging is the last chance to see what’s really going to production. more in the glossary → before merging into the deploy branch — a merge ships every commit on the source, including other sessions’ work: git log <deploy>..<source> --oneline. An urgent isolated fix is Cherry-pick — Copying one chosen commit from one branch to another, without the rest of the changes. It ships an urgent fix without the unfinished work next to it — but check the result, as it can pull in neighbouring hunks. more in the glossary →.
  4. After any cherry-pick, verify the result: git diff <deploy-base> HEAD --stat must show only your change — a 3-way fallback can drag in a neighbour’s hunk (a stray require → boot crash → 502).
  5. One concurrent session = one git worktree — A separate working copy of the same repository, so a second parallel session works in its own folder and doesn’t clash with the first. Two sessions in one folder overwrite each other’s work; a separate working tree prevents it. more in the glossary →, never two sessions in one checkout (→ 16).

Branching grows with the project — add each rung when a metric forces it:

  1. Solo, no live users → just main, committed to with discipline.
  2. First production deploy → every change on a short branch, reviewed, merged to an always-deployable main, deploy tagged.
  3. More people / parallel streams → develop for integration, releases develop → main, verified on a preprod copy of prod first (→ 18).

Every change reaches main reviewed — solo, the reviewer is a deliberate second pass over the diff.

Deployments — the overriding policy

⛔ Never deploy to prod automatically. Pull on the server, reload, Migration (database) — A controlled change to the database layout — adding a column, a table or moving data — step by step. Like a renovation to plan: rebuilding data in a set order so nothing “collapses”. more in the glossary →, database swap, the Maintenance window — A short, planned period when users see a “work in progress” page while the database or configuration changes behind it. It guarantees the app never runs, even briefly, on half-changed data. more in the glossary → flag — only on the user’s explicit “deploy”. You may propose a deploy; you wait for the yes. Commit and push are not a deploy. This rule beats any auto mode.

  1. The server deploys origin/<branch>, not your laptop. Before every deploy: git fetch, then git log origin/<b>..<b> (unpushed commits → push first) and git log <b>..origin/<b> (another session pushed → pull first).
  2. Boot-check on the target before reloading: after the pull, start the new code in a throwaway process (node -e "require('./src/app')", with listen behind require.main === module); reload only on its OK marker. A crash then leaves the old process serving.
  3. Two deploy types. Code-only → pull + boot-check + zero-downtime reload. Migration / dependency change / database swap → a maintenance window (branded 503 page) so nothing runs on a half-migrated schema.
  4. Tag every deploy: git tag -a deploy-$(date +%F) -m "<what goes live>" + git push --tags. What’s live: git describe --tags --abbrev=0 --match 'deploy-*'. Code Rollback — Reverting a change to the previous, working state — “Ctrl+Z” for a deployment. When a new version breaks production, a rollback restores the previous one in seconds instead of fixing in a panic. more in the glossary → = checkout the tag + reload; schema rollback = restore the Backup — A copy of your data saved earlier, which you return to when something goes wrong. It’s the only way to undo a change to data — code comes back from git, data only from a backup. more in the glossary →.
  5. Every deploy updates the public changelog in plain language — what the user gains.
  6. Every prod incident becomes a dated, numbered lesson in the Runbook — A written step-by-step guide for production operations, with numbered lessons from incidents. The memory of outages can’t live in someone’s head — the next deploy starts by reading the runbook. more in the glossary → (docs/), read before the next deploy (→ 14).
  7. First real users = a nightly database backup, deploy tags and a branded maintenance page — all on day one of traffic.

Anti-patterns

  • 🚫 Auto-deploy, “it’s ready so it goes”.
  • 🚫 Deploying without reconciling local ⇄ origin — unpushed commits silently don’t ship.
  • 🚫 Merging a shared branch into the deploy branch without reading what it brings.
  • 🚫 A long-lived “big refactor” branch; an “everything at once” PR.
  • 🚫 Working without an issue — the “why” is gone a month later.
  • 🚫 No deploy tag — “what’s live?” becomes guesswork.
  • 🚫 A deploy-script invariant with no test ($(date) expanded once → every backup overwrites the same file).
Chapter deep-dive 05Why these rules, examples and stories from projects — what the core deliberately leaves out.

The canonical doctrine is written in English.