{"id":"ade506c1-b38e-4d7c-b636-70083229d141","shortId":"m5TyJy","kind":"skill","title":"git-squash","tagline":"This skill should be used when the user asks to \"squash PR commits\", \"squash my branch\", \"flatten branch history\", \"combine all commits into one\", \"prepare a clean PR commit\", or \"squash commits relative to main/default branch\". It rewrites the current branch into a single commit","description":"# Git Squash\n\nSquash the current PR branch into one commit based on net branch changes relative to the default branch. Do not create or invoke a helper script. Run the Git commands directly.\n\n## Arguments\n\nParse `$ARGUMENTS` for optional flags:\n\n- `--subject <line>`: Override the generated commit subject line\n- `--base <branch>`: Override default-branch auto-detection\n\nDefaults:\n\n- Subject: infer a conventional-commit subject from the squashed changes themselves; do not default to `chore`\n- Base detection order:\n  1. `refs/remotes/origin/HEAD`\n  2. `git remote show origin`\n  3. `main`, `master`, `trunk`\n\n## Workflow\n\n### 1) Pre-flight\n\nStart by confirming that history can be rewritten safely. Stop on the first failure.\n\n- Verify inside a Git worktree: `git rev-parse --is-inside-work-tree`\n- Verify not detached: `git symbolic-ref --quiet --short HEAD`\n- Verify working tree is clean: `git status --porcelain`\n- After base detection, stop if the current branch is the default branch\n\n```bash\ngit rev-parse --is-inside-work-tree\ngit symbolic-ref --quiet --short HEAD\ngit status --porcelain\n```\n\n### 2) Resolve the Base Branch\n\nIf `--base` was provided, use that branch name directly. Otherwise, detect the default branch in this order:\n\n1. `refs/remotes/origin/HEAD`\n2. `git remote show origin`\n3. `main`, `master`, `trunk`\n\nAfter the branch name is resolved, normalize it to a usable ref by preferring the local branch and falling back to `origin/<branch>`. Stop if neither exists. Also stop if the current branch is the default branch, because the skill should never squash the default branch into itself.\n\n```bash\ngit symbolic-ref --quiet --short refs/remotes/origin/HEAD\ngit remote show origin\ngit show-ref --verify --quiet \"refs/heads/$default_branch\"\ngit show-ref --verify --quiet \"refs/remotes/origin/$default_branch\"\n```\n\n### 3) Find the Squash Boundary\n\nCompute the merge-base between `HEAD` and the resolved default ref. That merge-base is the point where the branch diverged. Count how many commits are ahead of it. If the count is zero, there is nothing to squash.\n\n```bash\nmerge_base=\"$(git merge-base HEAD \"$default_ref\")\"\nahead_count=\"$(git rev-list --count \"$merge_base..HEAD\")\"\noriginal_head=\"$(git rev-parse HEAD)\"\n```\n\n### 4) Collect Semantic Context Before Rewriting\n\nInspect the commits that will be squashed before mutating history. Use them to understand intent and distinct workstreams, but treat the staged net diff as the source of truth for what survives.\n\n- Read the commit list in chronological order: `git log --reverse --format='%H%x09%s' \"$merge_base..HEAD\"`\n- If subjects are vague or mixed, inspect the most important commits more deeply with `git show --stat --summary --format=fuller <commit>`\n- Identify the dominant user-visible or developer-visible outcomes\n- Ignore intermediate work that does not survive in the final diff\n- Collect all unique authors from the squashed commits and identify which are co-authors (anyone other than the committer of the squash commit). Use `git log --format='%aN <%aE>' \"$merge_base..HEAD\" | sort -u` to get the list, then exclude the current user (`git config user.name` / `git config user.email`). Each remaining author becomes a `Co-authored-by` trailer\n\nYou are not writing a changelog of every commit. You are deriving one accurate commit message for the final net change.\n\n### 5) Rewrite the Branch into a Single Staged Diff\n\nSoft-reset to the merge-base. This keeps the branch's net changes staged while removing the intermediate commits from history. If the staged diff is empty after the reset, restore the original head and stop with an error, because there is no net change to commit.\n\n```bash\ngit reset --soft \"$merge_base\"\ngit diff --cached --quiet\ngit reset --soft \"$original_head\"\n```\n\n### 6) Build the Commit Message from Commits + Net Diff\n\nUse `--subject` when provided. Otherwise, generate a conventional-commit subject by semantically analyzing:\n\n- all commits in `\"$merge_base..HEAD\"`\n- the staged net diff after the soft reset\n- targeted hunks from `git diff --cached` when the summary is ambiguous\n\nInfer the commit type from the surviving change, not from the fact that a squash happened:\n\n- New functionality -> `feat`\n- Bug fix -> `fix`\n- Refactor without behavior change -> `refactor`\n- Docs only -> `docs`\n- Tests only -> `test`\n- Build or tooling -> `build`\n- CI workflow -> `ci`\n- Dependency updates -> `chore(deps)`\n- Formatting only -> `style`\n- Performance -> `perf`\n- AI agent/config updates -> `ai`\n- General maintenance -> `chore`\n\nDo not default to `chore` unless the net change is actually maintenance work.\n\nSubject requirements:\n\n- Format: `type(scope): description` or `type: description`\n- Imperative mood, lowercase, no trailing period\n- Describe what changed in English, not that commits were squashed\n- Keep it specific; `feat(streaming): add batch cancel support` is acceptable, `chore: squash branch changes` is not\n- Keep it short enough for a normal Git subject line\n\nBody requirements:\n\n- Describe only net changes that still exist after the squash\n- Use 1-5 hyphen bullets for non-trivial changes\n- Summarize distinct behavior, API, data model, tooling, test, or documentation changes in natural language\n- Mention filenames or raw path lists only when a name is semantically necessary for clarity\n- Do not dump `shortstat`, `name-status`, or file inventories into the message\n- Skip the body entirely if the change is small and the subject fully captures it\n\nValidation requirements before committing:\n\n- If the message reads like a file listing, stats dump, or \"squash net changes\" meta-commentary, rewrite it\n- If multiple commits were squashed but only one net concern remains, write one focused message for that concern\n- If several distinct net concerns remain, reflect them as concise bullets in the body\n- Make sure every bullet is supported by the staged diff\n\nHelpful commands:\n\n```bash\ngit log --reverse --format='%H%x09%s' \"$merge_base..HEAD\"\ngit diff --cached --stat\ngit diff --cached\n```\n\nIf co-authors were collected in step 4, append a blank line followed by one `Co-authored-by: Name <email>` trailer per co-author at the end of the message. Do not add trailers for the current user.\n\nWrite the final message to a temporary file and commit with `git commit -F`.\n\n### 7) Report the Result\n\nAfter the commit succeeds:\n\n- Report how many commits were squashed\n- Report which default ref was used\n- If the branch already exists on remote, remind the user to force-push with lease\n\n```bash\ngit commit -F \"$message_file\"\ngit push --force-with-lease\n```\n\n## Behavior\n\n- Stop immediately if not inside a git repository.\n- Stop immediately if the current branch is the default branch.\n- Stop if the working tree is dirty, to avoid mixing unrelated local edits.\n- Inspect the commits being squashed before rewriting history.\n- Reset softly to the merge-base with the default branch.\n- Commit staged net changes as a single commit.\n- Generate a semantic commit message grounded in the net diff and informed by all commits being squashed.\n- Never use a fixed fallback like `chore: squash <branch> net changes` unless the user explicitly provided `--subject`.\n\n## Output\n\n- Prints how many commits were squashed.\n- Prints the resolved default branch reference.\n- Prints a reminder to force-push with lease when the branch already exists on remote.","tags":["git","squash","agent","skills","paulrberg","agent-skills","ai-agents"],"capabilities":["skill","source-paulrberg","skill-git-squash","topic-agent-skills","topic-ai-agents"],"categories":["agent-skills"],"synonyms":[],"warnings":[],"endpointUrl":"https://skills.sh/PaulRBerg/agent-skills/git-squash","protocol":"skill","transport":"skills-sh","auth":{"type":"none","details":{"cli":"npx skills add PaulRBerg/agent-skills","source_repo":"https://github.com/PaulRBerg/agent-skills","install_from":"skills.sh"}},"qualityScore":"0.475","qualityRationale":"deterministic score 0.47 from registry signals: · indexed on github topic:agent-skills · 50 github stars · SKILL.md body (7,384 chars)","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-github:v1","enrichmentVersion":1,"enrichedAt":"2026-04-22T00:56:18.456Z","embedding":null,"createdAt":"2026-04-18T22:17:45.610Z","updatedAt":"2026-04-22T00:56:18.456Z","lastSeenAt":"2026-04-22T00:56:18.456Z","tsv":"'-5':835 '1':124,136,240,834 '2':126,218,242 '3':131,247,328 '4':401,993 '5':579 '6':652 '7':1039 'accept':804 'accur':571 'actual':766 'add':799,1019 'ae':527 'agent/config':750 'ahead':361,384 'ai':749,752 'alreadi':1062,1204 'also':277 'ambigu':699 'analyz':674 'anyon':513 'api':846 'append':994 'argument':82,84 'ask':12 'author':501,512,550,555,988,1003,1010 'auto':101 'auto-detect':100 'avoid':1114 'back':270 'base':59,95,121,187,221,224,337,348,376,380,392,454,529,595,642,679,976,1133 'bash':198,298,374,637,967,1075 'batch':800 'becom':551 'behavior':724,845,1087 'blank':996 'bodi':821,887,954 'boundari':332 'branch':19,21,39,44,55,62,68,99,193,197,222,229,236,253,267,282,286,295,318,327,354,582,599,807,1061,1101,1105,1137,1190,1203 'bug':719 'build':653,733,736 'bullet':837,951,958 'cach':645,694,980,984 'cancel':801 'captur':898 'chang':63,114,578,602,634,707,725,764,786,808,826,842,853,891,917,1141,1172 'changelog':563 'chore':120,742,755,760,805,1169 'chronolog':444 'ci':737,739 'clariti':871 'clean':30,182 'co':511,554,987,1002,1009 'co-author':510,986,1008 'co-authored-bi':553,1001 'collect':402,498,990 'combin':23 'command':80,966 'commentari':920 'commit':16,25,32,35,48,58,92,109,359,409,441,466,505,521,566,572,608,636,655,658,670,676,702,791,903,925,1034,1037,1045,1050,1077,1121,1138,1145,1149,1160,1183 'committ':517 'comput':333 'concern':932,940,945 'concis':950 'config':543,546 'confirm':142 'context':404 'convent':108,669 'conventional-commit':107,668 'count':356,366,385,390 'creat':71 'current':43,53,192,281,540,1023,1100 'data':847 'deepli':468 'default':67,98,103,118,196,235,285,294,317,326,343,382,758,1055,1104,1136,1189 'default-branch':97 'dep':743 'depend':740 'deriv':569 'describ':784,823 'descript':774,777 'detach':170 'detect':102,122,188,233 'develop':484 'developer-vis':483 'diff':430,497,587,614,644,660,684,693,964,979,983,1155 'direct':81,231 'dirti':1112 'distinct':423,844,943 'diverg':355 'doc':727,729 'document':852 'domin':478 'dump':874,913 'edit':1118 'empti':616 'end':1013 'english':788 'enough':814 'entir':888 'error':628 'everi':565,957 'exclud':538 'exist':276,829,1063,1205 'explicit':1176 'f':1038,1078 'fact':711 'failur':153 'fall':269 'fallback':1167 'feat':718,797 'file':880,910,1032,1080 'filenam':858 'final':496,576,1027 'find':329 'first':152 'fix':720,721,1166 'flag':87 'flatten':20 'flight':139 'focus':936 'follow':998 'forc':1071,1084,1197 'force-push':1070,1196 'force-with-leas':1083 'format':449,474,525,744,771,971 'fuller':475 'fulli':897 'function':717 'general':753 'generat':91,666,1146 'get':534 'git':2,49,79,127,157,159,171,183,199,208,215,243,299,306,310,319,377,386,396,446,470,523,542,545,638,643,647,692,818,968,978,982,1036,1076,1081,1094 'git-squash':1 'ground':1151 'h':450,972 'happen':715 'head':177,214,339,381,393,395,400,455,530,623,651,680,977 'help':965 'helper':75 'histori':22,144,416,610,1126 'hunk':690 'hyphen':836 'identifi':476,507 'ignor':487 'immedi':1089,1097 'imper':778 'import':465 'infer':105,700 'inform':1157 'insid':155,165,205,1092 'inspect':407,462,1119 'intent':421 'intermedi':488,607 'inventori':881 'invok':73 'is-inside-work-tre':163,203 'keep':597,794,811 'languag':856 'leas':1074,1086,1200 'like':908,1168 'line':94,820,997 'list':389,442,536,862,911 'local':266,1117 'log':447,524,969 'lowercas':780 'main':132,248 'main/default':38 'mainten':754,767 'make':955 'mani':358,1049,1182 'master':133,249 'mention':857 'merg':336,347,375,379,391,453,528,594,641,678,975,1132 'merge-bas':335,346,378,593,1131 'messag':573,656,884,906,937,1016,1028,1079,1150 'meta':919 'meta-commentari':918 'mix':461,1115 'model':848 'mood':779 'multipl':924 'mutat':415 'name':230,254,866,877,1005 'name-status':876 'natur':855 'necessari':869 'neither':275 'net':61,429,577,601,633,659,683,763,825,916,931,944,1140,1154,1171 'never':291,1163 'new':716 'non':840 'non-trivi':839 'normal':257,817 'noth':371 'one':27,57,570,930,935,1000 'option':86 'order':123,239,445 'origin':130,246,272,309,394,622,650 'otherwis':232,665 'outcom':486 'output':1179 'overrid':89,96 'pars':83,162,202,399 'path':861 'per':1007 'perf':748 'perform':747 'period':783 'point':351 'porcelain':185,217 'pr':15,31,54 'pre':138 'pre-flight':137 'prefer':264 'prepar':28 'print':1180,1186,1192 'provid':226,664,1177 'push':1072,1082,1198 'quiet':175,212,303,315,324,646 'raw':860 'read':439,907 'ref':174,211,262,302,313,322,344,383,1056 'refactor':722,726 'refer':1191 'reflect':947 'refs/heads':316 'refs/remotes/origin':325 'refs/remotes/origin/head':125,241,305 'relat':36,64 'remain':549,933,946 'remind':1066,1194 'remot':128,244,307,1065,1207 'remov':605 'report':1040,1047,1053 'repositori':1095 'requir':770,822,901 'reset':590,619,639,648,688,1127 'resolv':219,256,342,1188 'restor':620 'result':1042 'rev':161,201,388,398 'rev-list':387 'rev-pars':160,200,397 'revers':448,970 'rewrit':41,406,580,921,1125 'rewritten':147 'run':77 'safe':148 'scope':773 'script':76 'semant':403,673,868,1148 'sever':942 'short':176,213,304,813 'shortstat':875 'show':129,245,308,312,321,471 'show-ref':311,320 'singl':47,585,1144 'skill':5,289 'skill-git-squash' 'skip':885 'small':893 'soft':589,640,649,687,1128 'soft-reset':588 'sort':531 'sourc':433 'source-paulrberg' 'specif':796 'squash':3,14,17,34,50,51,113,292,331,373,413,504,520,714,793,806,832,915,927,1052,1123,1162,1170,1185 'stage':428,586,603,613,682,963,1139 'start':140 'stat':472,912,981 'status':184,216,878 'step':992 'still':828 'stop':149,189,273,278,625,1088,1096,1106 'stream':798 'style':746 'subject':88,93,104,110,457,662,671,769,819,896,1178 'succeed':1046 'summar':843 'summari':473,697 'support':802,960 'sure':956 'surviv':438,493,706 'symbol':173,210,301 'symbolic-ref':172,209,300 'target':689 'temporari':1031 'test':730,732,850 'tool':735,849 'topic-agent-skills' 'topic-ai-agents' 'trail':782 'trailer':557,1006,1020 'treat':426 'tree':167,180,207,1110 'trivial':841 'trunk':134,250 'truth':435 'type':703,772,776 'u':532 'understand':420 'uniqu':500 'unless':761,1173 'unrel':1116 'updat':741,751 'usabl':261 'use':8,227,417,522,661,833,1058,1164 'user':11,480,541,1024,1068,1175 'user-vis':479 'user.email':547 'user.name':544 'vagu':459 'valid':900 'verifi':154,168,178,314,323 'visibl':481,485 'without':723 'work':166,179,206,489,768,1109 'workflow':135,738 'workstream':424 'worktre':158 'write':561,934,1025 'x09':451,973 'zero':368","prices":[{"id":"5990e942-3c66-451f-8acd-354efff780c7","listingId":"ade506c1-b38e-4d7c-b636-70083229d141","amountUsd":"0","unit":"free","nativeCurrency":null,"nativeAmount":null,"chain":null,"payTo":null,"paymentMethod":"skill-free","isPrimary":true,"details":{"org":"PaulRBerg","category":"agent-skills","install_from":"skills.sh"},"createdAt":"2026-04-18T22:17:45.610Z"}],"sources":[{"listingId":"ade506c1-b38e-4d7c-b636-70083229d141","source":"github","sourceId":"PaulRBerg/agent-skills/git-squash","sourceUrl":"https://github.com/PaulRBerg/agent-skills/tree/main/skills/git-squash","isPrimary":false,"firstSeenAt":"2026-04-18T22:17:45.610Z","lastSeenAt":"2026-04-22T00:56:18.456Z"}],"details":{"listingId":"ade506c1-b38e-4d7c-b636-70083229d141","quickStartSnippet":null,"exampleRequest":null,"exampleResponse":null,"schema":null,"openapiUrl":null,"agentsTxtUrl":null,"citations":[],"useCases":[],"bestFor":[],"notFor":[],"kindDetails":{"org":"PaulRBerg","slug":"git-squash","github":{"repo":"PaulRBerg/agent-skills","stars":50,"topics":["agent-skills","ai-agents"],"license":"mit","html_url":"https://github.com/PaulRBerg/agent-skills","pushed_at":"2026-04-20T16:22:56Z","description":"PRB's collection of agent skills","skill_md_sha":"5989449f7f25bdff7f017a0c663ebb9ebfc823d7","skill_md_path":"skills/git-squash/SKILL.md","default_branch":"main","skill_tree_url":"https://github.com/PaulRBerg/agent-skills/tree/main/skills/git-squash"},"layout":"multi","source":"github","category":"agent-skills","frontmatter":{"name":"git-squash","description":"This skill should be used when the user asks to \"squash PR commits\", \"squash my branch\", \"flatten branch history\", \"combine all commits into one\", \"prepare a clean PR commit\", or \"squash commits relative to main/default branch\". It rewrites the current branch into a single commit whose message semantically summarizes the surviving net changes relative to the default branch."},"skills_sh_url":"https://skills.sh/PaulRBerg/agent-skills/git-squash"},"updatedAt":"2026-04-22T00:56:18.456Z"}}