{"id":"61d6c9a7-904e-4d90-bc1b-d27cbb708583","shortId":"XXJ5NX","kind":"skill","title":"Git Workflow And Versioning","tagline":"Agent Skills skill by Addyosmani","description":"# Git Workflow and Versioning\n\n## Overview\n\nGit is your safety net. Treat commits as save points, branches as sandboxes, and history as documentation. With AI agents generating code at high speed, disciplined version control is the mechanism that keeps changes manageable, reviewable, and reversible.\n\n## When to Use\n\nAlways. Every code change flows through git.\n\n## Core Principles\n\n### Trunk-Based Development (Recommended)\n\nKeep `main` always deployable. Work in short-lived feature branches that merge back within 1-3 days. Long-lived development branches are hidden costs — they diverge, create merge conflicts, and delay integration. DORA research consistently shows trunk-based development correlates with high-performing engineering teams.\n\n```\nmain ──●──●──●──●──●──●──●──●──●──  (always deployable)\n        ╲      ╱  ╲    ╱\n         ●──●─╱    ●──╱    ← short-lived feature branches (1-3 days)\n```\n\nThis is the recommended default. Teams using gitflow or long-lived branches can adapt the principles (atomic commits, small changes, descriptive messages) to their branching model — the commit discipline matters more than the specific branching strategy.\n\n- **Dev branches are costs.** Every day a branch lives, it accumulates merge risk.\n- **Release branches are acceptable.** When you need to stabilize a release while main moves forward.\n- **Feature flags > long branches.** Prefer deploying incomplete work behind flags rather than keeping it on a branch for weeks.\n\n### 1. Commit Early, Commit Often\n\nEach successful increment gets its own commit. Don't accumulate large uncommitted changes.\n\n```\nWork pattern:\n  Implement slice → Test → Verify → Commit → Next slice\n\nNot this:\n  Implement everything → Hope it works → Giant commit\n```\n\nCommits are save points. If the next change breaks something, you can revert to the last known-good state instantly.\n\n### 2. Atomic Commits\n\nEach commit does one logical thing:\n\n```\n# Good: Each commit is self-contained\ngit log --oneline\na1b2c3d Add task creation endpoint with validation\nd4e5f6g Add task creation form component\nh7i8j9k Connect form to API and add loading state\nm1n2o3p Add task creation tests (unit + integration)\n\n# Bad: Everything mixed together\ngit log --oneline\nx1y2z3a Add task feature, fix sidebar, update deps, refactor utils\n```\n\n### 3. Descriptive Messages\n\nCommit messages explain the *why*, not just the *what*:\n\n```\n# Good: Explains intent\nfeat: add email validation to registration endpoint\n\nPrevents invalid email formats from reaching the database.\nUses Zod schema validation at the route handler level,\nconsistent with existing validation patterns in auth.ts.\n\n# Bad: Describes what's obvious from the diff\nupdate auth.ts\n```\n\n**Format:**\n```\n<type>: <short description>\n\n<optional body explaining why, not what>\n```\n\n**Types:**\n- `feat` — New feature\n- `fix` — Bug fix\n- `refactor` — Code change that neither fixes a bug nor adds a feature\n- `test` — Adding or updating tests\n- `docs` — Documentation only\n- `chore` — Tooling, dependencies, config\n\n### 4. Keep Concerns Separate\n\nDon't combine formatting changes with behavior changes. Don't combine refactors with features. Each type of change should be a separate commit — and ideally a separate PR:\n\n```\n# Good: Separate concerns\ngit commit -m \"refactor: extract validation logic to shared utility\"\ngit commit -m \"feat: add phone number validation to registration\"\n\n# Bad: Mixed concerns\ngit commit -m \"refactor validation and add phone number field\"\n```\n\n**Separate refactoring from feature work.** A refactoring change and a feature change are two different changes — submit them separately. This makes each change easier to review, revert, and understand in history. Small cleanups (renaming a variable) can be included in a feature commit at reviewer discretion.\n\n### 5. Size Your Changes\n\nTarget ~100 lines per commit/PR. Changes over ~1000 lines should be split. See the splitting strategies in `code-review-and-quality` for how to break down large changes.\n\n```\n~100 lines  → Easy to review, easy to revert\n~300 lines  → Acceptable for a single logical change\n~1000 lines → Split into smaller changes\n```\n\n## Branching Strategy\n\n### Feature Branches\n\n```\nmain (always deployable)\n  │\n  ├── feature/task-creation    ← One feature per branch\n  ├── feature/user-settings    ← Parallel work\n  └── fix/duplicate-tasks      ← Bug fixes\n```\n\n- Branch from `main` (or the team's default branch)\n- Keep branches short-lived (merge within 1-3 days) — long-lived branches are hidden costs\n- Delete branches after merge\n- Prefer feature flags over long-lived branches for incomplete features\n\n### Branch Naming\n\n```\nfeature/<short-description>   → feature/task-creation\nfix/<short-description>       → fix/duplicate-tasks\nchore/<short-description>     → chore/update-deps\nrefactor/<short-description>  → refactor/auth-module\n```\n\n## Working with Worktrees\n\nFor parallel AI agent work, use git worktrees to run multiple branches simultaneously:\n\n```bash\n# Create a worktree for a feature branch\ngit worktree add ../project-feature-a feature/task-creation\ngit worktree add ../project-feature-b feature/user-settings\n\n# Each worktree is a separate directory with its own branch\n# Agents can work in parallel without interfering\nls ../\n  project/              ← main branch\n  project-feature-a/    ← task-creation branch\n  project-feature-b/    ← user-settings branch\n\n# When done, merge and clean up\ngit worktree remove ../project-feature-a\n```\n\nBenefits:\n- Multiple agents can work on different features simultaneously\n- No branch switching needed (each directory has its own branch)\n- If one experiment fails, delete the worktree — nothing is lost\n- Changes are isolated until explicitly merged\n\n## The Save Point Pattern\n\n```\nAgent starts work\n    │\n    ├── Makes a change\n    │   ├── Test passes? → Commit → Continue\n    │   └── Test fails? → Revert to last commit → Investigate\n    │\n    ├── Makes another change\n    │   ├── Test passes? → Commit → Continue\n    │   └── Test fails? → Revert to last commit → Investigate\n    │\n    └── Feature complete → All commits form a clean history\n```\n\nThis pattern means you never lose more than one increment of work. If an agent goes off the rails, `git reset --hard HEAD` takes you back to the last successful state.\n\n## Change Summaries\n\nAfter any modification, provide a structured summary. This makes review easier, documents scope discipline, and surfaces unintended changes:\n\n```\nCHANGES MADE:\n- src/routes/tasks.ts: Added validation middleware to POST endpoint\n- src/lib/validation.ts: Added TaskCreateSchema using Zod\n\nTHINGS I DIDN'T TOUCH (intentionally):\n- src/routes/auth.ts: Has similar validation gap but out of scope\n- src/middleware/error.ts: Error format could be improved (separate task)\n\nPOTENTIAL CONCERNS:\n- The Zod schema is strict — rejects extra fields. Confirm this is desired.\n- Added zod as a dependency (72KB gzipped) — already in package.json\n```\n\nThis pattern catches wrong assumptions early and gives reviewers a clear map of the change. The \"DIDN'T TOUCH\" section is especially important — it shows you exercised scope discipline and didn't go on an unsolicited renovation.\n\n## Pre-Commit Hygiene\n\nBefore every commit:\n\n```bash\n# 1. Check what you're about to commit\ngit diff --staged\n\n# 2. Ensure no secrets\ngit diff --staged | grep -i \"password\\|secret\\|api_key\\|token\"\n\n# 3. Run tests\nnpm test\n\n# 4. Run linting\nnpm run lint\n\n# 5. Run type checking\nnpx tsc --noEmit\n```\n\nAutomate this with git hooks:\n\n```json\n// package.json (using lint-staged + husky)\n{\n  \"lint-staged\": {\n    \"*.{ts,tsx}\": [\"eslint --fix\", \"prettier --write\"],\n    \"*.{json,md}\": [\"prettier --write\"]\n  }\n}\n```\n\n## Handling Generated Files\n\n- **Commit generated files** only if the project expects them (e.g., `package-lock.json`, Prisma migrations)\n- **Don't commit** build output (`dist/`, `.next/`), environment files (`.env`), or IDE config (`.vscode/settings.json` unless shared)\n- **Have a `.gitignore`** that covers: `node_modules/`, `dist/`, `.env`, `.env.local`, `*.pem`\n\n## Using Git for Debugging\n\n```bash\n# Find which commit introduced a bug\ngit bisect start\ngit bisect bad HEAD\ngit bisect good <known-good-commit>\n# Git checkouts midpoints; run your test at each to narrow down\n\n# View what changed recently\ngit log --oneline -20\ngit diff HEAD~5..HEAD -- src/\n\n# Find who last changed a specific line\ngit blame src/services/task.ts\n\n# Search commit messages for a keyword\ngit log --grep=\"validation\" --oneline\n```\n\n## Common Rationalizations\n\n| Rationalization | Reality |\n|---|---|\n| \"I'll commit when the feature is done\" | One giant commit is impossible to review, debug, or revert. Commit each slice. |\n| \"The message doesn't matter\" | Messages are documentation. Future you (and future agents) will need to understand what changed and why. |\n| \"I'll squash it all later\" | Squashing destroys the development narrative. Prefer clean incremental commits from the start. |\n| \"Branches add overhead\" | Short-lived branches are free and prevent conflicting work from colliding. Long-lived branches are the problem — merge within 1-3 days. |\n| \"I'll split this change later\" | Large changes are harder to review, riskier to deploy, and harder to revert. Split before submitting, not after. |\n| \"I don't need a .gitignore\" | Until `.env` with production secrets gets committed. Set it up immediately. |\n\n## Red Flags\n\n- Large uncommitted changes accumulating\n- Commit messages like \"fix\", \"update\", \"misc\"\n- Formatting changes mixed with behavior changes\n- No `.gitignore` in the project\n- Committing `node_modules/`, `.env`, or build artifacts\n- Long-lived branches that diverge significantly from main\n- Force-pushing to shared branches\n\n## Verification\n\nFor every commit:\n\n- [ ] Commit does one logical thing\n- [ ] Message explains the why, follows type conventions\n- [ ] Tests pass before committing\n- [ ] No secrets in the diff\n- [ ] No formatting-only changes mixed with behavior changes\n- [ ] `.gitignore` covers standard exclusions","tags":["git","workflow","and","versioning","agent","skills","addyosmani"],"capabilities":["skill","source-addyosmani","category-agent-skills"],"categories":["agent-skills"],"synonyms":[],"warnings":[],"endpointUrl":"https://skills.sh/addyosmani/agent-skills/git-workflow-and-versioning","protocol":"skill","transport":"skills-sh","auth":{"type":"none","details":{"install_from":"skills.sh"}},"qualityScore":"0.300","qualityRationale":"deterministic score 0.30 from registry signals: · indexed on skills.sh · published under addyosmani/agent-skills","verified":false,"liveness":"unknown","lastLivenessCheck":null,"agentReviews":{"count":0,"score_avg":null,"cost_usd_avg":null,"success_rate":null,"latency_p50_ms":null,"narrative_summary":null,"summary_updated_at":null},"enrichmentModel":"deterministic:skill:v1","enrichmentVersion":1,"enrichedAt":"2026-04-22T10:40:33.115Z","embedding":null,"createdAt":"2026-04-18T20:32:20.729Z","updatedAt":"2026-04-22T10:40:33.115Z","lastSeenAt":"2026-04-22T10:40:33.115Z","tsv":"'-20':1134 '-3':86,128,634,1251 '/project-feature-a':695,748 '/project-feature-b':700 '1':85,127,214,633,984,1250 '100':549,577 '1000':555,593 '2':271,995 '3':336,1009 '300':585 '4':430,1014 '5':544,1020 '72kb':934 'a1b2c3d':290 'accept':183,587 'accumul':177,228,1299 'ad':419,881,888,929 'adapt':144 'add':291,298,309,313,327,352,415,479,494,694,699,1227 'addyosmani':9 'agent':5,34,674,712,751,788,841,1199 'ai':33,673 'alreadi':936 'alway':56,72,120,604 'anoth':806 'api':307,1006 'artifact':1323 'assumpt':943 'atom':147,272 'auth.ts':381,391 'autom':1027 'b':734 'back':83,852 'bad':319,382,485,1111 'base':67,110 'bash':684,983,1099 'behavior':440,1310,1371 'behind':203 'benefit':749 'bisect':1107,1110,1114 'blame':1149 'bodi':394 'branch':25,80,92,126,142,155,165,168,174,181,198,211,599,602,610,617,625,627,639,644,654,658,682,691,711,722,730,738,759,767,1226,1232,1244,1327,1338 'break':258,573 'bug':404,413,615,1105 'build':1071,1322 'catch':941 'category-agent-skills' 'chang':48,59,150,231,257,408,438,441,451,505,509,513,520,547,553,576,592,598,778,793,807,858,877,878,953,1129,1144,1205,1257,1260,1298,1307,1311,1368,1372 'check':985,1023 'checkout':1117 'chore':426,664 'chore/update-deps':665 'clean':743,825,1220 'cleanup':530 'clear':949 'code':36,58,407,566 'code-review-and-qu':565 'collid':1240 'combin':436,444 'commit':21,148,158,215,217,225,238,249,250,273,275,282,339,456,466,476,489,540,796,803,810,817,822,978,982,991,1055,1070,1102,1152,1168,1176,1184,1222,1289,1300,1317,1342,1343,1358 'commit/pr':552 'common':1162 'complet':820 'compon':302 'concern':432,464,487,916 'config':429,1080 'confirm':925 'conflict':100,1237 'connect':304 'consist':106,375 'contain':286 'continu':797,811 'control':42 'convent':1354 'core':63 'correl':112 'cost':95,170,642 'could':910 'cover':1088,1374 'creat':98,685 'creation':293,300,315,729 'd4e5f6g':297 'databas':365 'day':87,129,172,635,1252 'debug':1098,1181 'default':134,624 'delay':102 'delet':643,772 'dep':333 'depend':428,933 'deploy':73,121,200,605,1267 'describ':383 'descript':151,337 'desir':928 'destroy':1215 'dev':167 'develop':68,91,111,1217 'didn':894,955,969 'diff':389,993,1000,1136,1363 'differ':512,755 'directori':707,763 'disciplin':40,159,873,967 'discret':543 'dist':1073,1091 'diverg':97,1329 'doc':423 'document':31,424,871,1194 'doesn':1189 'done':740,1173 'dora':104 'e.g':1064 'earli':216,944 'easi':579,582 'easier':521,870 'email':353,360 'endpoint':294,357,886 'engin':117 'ensur':996 'env':1077,1092,1284,1320 'env.local':1093 'environ':1075 'error':908 'eslint':1044 'especi':960 'everi':57,171,981,1341 'everyth':244,320 'exclus':1376 'exercis':965 'exist':377 'expect':1062 'experi':770 'explain':341,349,395,1349 'explicit':782 'extra':923 'extract':469 'fail':771,799,813 'feat':351,400,478 'featur':79,125,195,329,402,417,447,501,508,539,601,608,648,657,660,690,725,733,756,819,1171 'feature/task-creation':606,661,696 'feature/user-settings':611,701 'field':497,924 'file':1054,1057,1076 'find':1100,1141 'fix':330,403,405,411,616,662,1045,1303 'fix/duplicate-tasks':614,663 'flag':196,204,649,1295 'flow':60 'follow':1352 'forc':1334 'force-push':1333 'form':301,305,823 'format':361,392,437,909,1306,1366 'formatting-on':1365 'forward':194 'free':1234 'futur':1195,1198 'gap':902 'generat':35,1053,1056 'get':222,1288 'giant':248,1175 'git':1,10,15,62,287,323,465,475,488,677,692,697,745,846,992,999,1030,1096,1106,1109,1113,1116,1131,1135,1148,1157 'gitflow':137 'gitignor':1086,1282,1313,1373 'give':946 'go':971 'goe':842 'good':268,280,348,462,1115 'grep':1002,1159 'gzip':935 'h7i8j9k':303 'handl':1052 'handler':373 'hard':848 'harder':1262,1269 'head':849,1112,1137,1139 'hidden':94,641 'high':38,115 'high-perform':114 'histori':29,528,826 'hook':1031 'hope':245 'huski':1038 'hygien':979 'ide':1079 'ideal':458 'immedi':1293 'implement':234,243 'import':961 'imposs':1178 'improv':912 'includ':536 'incomplet':201,656 'increment':221,836,1221 'instant':270 'integr':103,318 'intent':350,897 'interf':718 'introduc':1103 'invalid':359 'investig':804,818 'isol':780 'json':1032,1048 'keep':47,70,207,431,626 'key':1007 'keyword':1156 'known':267 'known-good':266 'larg':229,575,1259,1296 'last':265,802,816,855,1143 'later':1213,1258 'level':374 'like':1302 'line':550,556,578,586,594,1147 'lint':1016,1019,1036,1040 'lint-stag':1035,1039 'live':78,90,124,141,175,630,638,653,1231,1243,1326 'll':1167,1209,1254 'load':310 'log':288,324,1132,1158 'logic':278,471,591,1346 'long':89,140,197,637,652,1242,1325 'long-liv':88,139,636,651,1241,1324 'lose':832 'lost':777 'ls':719 'm':467,477,490 'm1n2o3p':312 'made':879 'main':71,119,192,603,619,721,1332 'make':518,791,805,868 'manag':49 'map':950 'matter':160,1191 'md':1049 'mean':829 'mechan':45 'merg':82,99,178,631,646,741,783,1248 'messag':152,338,340,1153,1188,1192,1301,1348 'middlewar':883 'midpoint':1118 'migrat':1067 'misc':1305 'mix':321,486,1308,1369 'model':156 'modif':862 'modul':1090,1319 'move':193 'multipl':681,750 'name':659 'narrat':1218 'narrow':1125 'need':186,761,1201,1280 'neither':410 'net':19 'never':831 'new':401 'next':239,256,1074 'node':1089,1318 'noemit':1026 'noth':775 'npm':1012,1017 'npx':1024 'number':481,496 'obvious':386 'often':218 'one':277,607,769,835,1174,1345 'onelin':289,325,1133,1161 'option':393 'output':1072 'overhead':1228 'overview':14 'package-lock.json':1065 'package.json':938,1033 'parallel':612,672,716 'pass':795,809,1356 'password':1004 'pattern':233,379,787,828,940 'pem':1094 'per':551,609 'perform':116 'phone':480,495 'point':24,253,786 'post':885 'potenti':915 'pr':461 'pre':977 'pre-commit':976 'prefer':199,647,1219 'prettier':1046,1050 'prevent':358,1236 'principl':64,146 'prisma':1066 'problem':1247 'product':1286 'project':720,724,732,1061,1316 'project-feature-a':723 'project-feature-b':731 'provid':863 'push':1335 'qualiti':569 'rail':845 'rather':205 'ration':1163,1164 're':988 'reach':363 'realiti':1165 'recent':1130 'recommend':69,133 'red':1294 'refactor':334,406,445,468,491,499,504,666 'refactor/auth-module':667 'registr':356,484 'reject':922 'releas':180,190 'remov':747 'renam':531 'renov':975 'research':105 'reset':847 'revers':52 'revert':262,524,584,800,814,1183,1271 'review':50,523,542,567,581,869,947,1180,1264 'risk':179 'riskier':1265 'rout':372 'run':680,1010,1015,1018,1021,1119 'safeti':18 'sandbox':27 'save':23,252,785 'schema':368,919 'scope':872,906,966 'search':1151 'secret':998,1005,1287,1360 'section':958 'see':560 'self':285 'self-contain':284 'separ':433,455,460,463,498,516,706,913 'set':737,1290 'share':473,1083,1337 'short':77,123,629,1230 'short-liv':76,122,628,1229 'show':107,963 'sidebar':331 'signific':1330 'similar':900 'simultan':683,757 'singl':590 'size':545 'skill':6,7 'slice':235,240,1186 'small':149,529 'smaller':597 'someth':259 'source-addyosmani' 'specif':164,1146 'speed':39 'split':559,562,595,1255,1272 'squash':1210,1214 'src':1140 'src/lib/validation.ts':887 'src/middleware/error.ts':907 'src/routes/auth.ts':898 'src/routes/tasks.ts':880 'src/services/task.ts':1150 'stabil':188 'stage':994,1001,1037,1041 'standard':1375 'start':789,1108,1225 'state':269,311,857 'strategi':166,563,600 'strict':921 'structur':865 'submit':514,1274 'success':220,856 'summari':859,866 'surfac':875 'switch':760 'take':850 'target':548 'task':292,299,314,328,728,914 'task-creat':727 'taskcreateschema':889 'team':118,135,622 'test':236,316,418,422,794,798,808,812,1011,1013,1121,1355 'thing':279,892,1347 'togeth':322 'token':1008 'tool':427 'touch':896,957 'treat':20 'trunk':66,109 'trunk-bas':65,108 'ts':1042 'tsc':1025 'tsx':1043 'two':511 'type':399,449,1022,1353 'uncommit':230,1297 'understand':526,1203 'unintend':876 'unit':317 'unless':1082 'unsolicit':974 'updat':332,390,421,1304 'use':55,136,366,676,890,1034,1095 'user':736 'user-set':735 'util':335,474 'valid':296,354,369,378,470,482,492,882,901,1160 'variabl':533 'verif':1339 'verifi':237 'version':4,13,41 'view':1127 'vscode/settings.json':1081 'week':213 'within':84,632,1249 'without':717 'work':74,202,232,247,502,613,668,675,714,753,790,838,1238 'workflow':2,11 'worktre':670,678,687,693,698,703,746,774 'write':1047,1051 'wrong':942 'x1y2z3a':326 'zod':367,891,918,930 '~5':1138","prices":[{"id":"409eedd4-077e-46f4-93a8-5b6c3640c15a","listingId":"61d6c9a7-904e-4d90-bc1b-d27cbb708583","amountUsd":"0","unit":"free","nativeCurrency":null,"nativeAmount":null,"chain":null,"payTo":null,"paymentMethod":"skill-free","isPrimary":true,"details":{"org":"addyosmani","category":"agent-skills","install_from":"skills.sh"},"createdAt":"2026-04-18T20:32:20.729Z"}],"sources":[{"listingId":"61d6c9a7-904e-4d90-bc1b-d27cbb708583","source":"github","sourceId":"addyosmani/agent-skills/git-workflow-and-versioning","sourceUrl":"https://github.com/addyosmani/agent-skills/tree/main/skills/git-workflow-and-versioning","isPrimary":false,"firstSeenAt":"2026-04-18T21:53:00.461Z","lastSeenAt":"2026-04-22T06:52:42.333Z"},{"listingId":"61d6c9a7-904e-4d90-bc1b-d27cbb708583","source":"skills_sh","sourceId":"addyosmani/agent-skills/git-workflow-and-versioning","sourceUrl":"https://skills.sh/addyosmani/agent-skills/git-workflow-and-versioning","isPrimary":true,"firstSeenAt":"2026-04-18T20:32:20.729Z","lastSeenAt":"2026-04-22T10:40:33.115Z"}],"details":{"listingId":"61d6c9a7-904e-4d90-bc1b-d27cbb708583","quickStartSnippet":null,"exampleRequest":null,"exampleResponse":null,"schema":null,"openapiUrl":null,"agentsTxtUrl":null,"citations":[],"useCases":[],"bestFor":[],"notFor":[],"kindDetails":{"org":"addyosmani","slug":"git-workflow-and-versioning","source":"skills_sh","category":"agent-skills","skills_sh_url":"https://skills.sh/addyosmani/agent-skills/git-workflow-and-versioning"},"updatedAt":"2026-04-22T10:40:33.115Z"}}