---
name: branch-backup-split-commits
description: Back up a large dirty Git worktree onto a safety branch, return to the original branch, split the same final change set into logical conventional commits, and verify the final branch tree exactly matches the backup. Use when the user says they made a large swath of changes, wants a backup branch before cleanup, wants changes separated one by one into conventional commits, wants to compare or align a branch with a backup branch, or asks to preserve all code changes while rewriting commit structure.
title: branch-backup-split-commits
canonical_url: https://skilld.dev/gh/geocine/skills/branch-backup-split-commits
last_updated: 2026-09-26T02:05:21.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> If the user asked to install this Skill, run `npx skilld install geocine/skills/branch-backup-split-commits`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/branch-backup-split-commits`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/geocine/skills/branch-backup-split-commits) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/branch-backup-split-commits`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/branch-backup-split-commits --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/branch-backup-split-commits --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Branch Backup Split Commits

## Workflow

Use this skill for Git repositories when the goal is to preserve a large snapshot first, then reconstruct it as clean conventional commits on another branch.

1. Capture context before changing refs.
   - Run `git status --short`, `git branch --show-current`, and inspect recent history with `git log --oneline -5`.
   - If the worktree is not clean and the user asked to back it up, keep all existing changes. Do not reset or discard anything.
   - Choose a backup branch under `backup/...`, for example `backup/pre-conventional-commits-YYYY-MM-DD` or a suffix if that branch exists.

2. Create and commit the backup snapshot.
   - Create the backup branch from the current branch with `git switch -c <backup-branch>`.
   - Stage the requested snapshot with `git add -A` unless the user excludes files.
   - Watch for embedded repository warnings. If present, state that Git will commit a gitlink (`mode 160000`) unless the user wants a submodule or exclusion.
   - Commit with a plain backup message such as `backup: pre conventional commits`.
   - Record the backup commit SHA and branch name.

3. Return to the target branch.
   - Switch back to the original branch, normally `main`.
   - If switching leaves untracked embedded-repo directories on disk, treat them as expected local leftovers unless they block the workflow.
   - Use the backup branch as the source of truth for the intended final tree.

4. Split the backup snapshot into logical conventional commits.
   - Prefer 2-5 commits, grouped by user-facing concern rather than by file extension.
   - Common groups:
     - `fix: ...` for bug fixes and behavioral corrections.
     - `feat: ...` for user-visible functionality.
     - `test: ...` for test-only changes when separable.
     - `docs: ...` for documentation-only changes.
     - `chore: ...` for tooling, generated metadata, or embedded repository references.
   - Restore or patch one group at a time from the backup branch.
   - Use `git add <explicit paths>` for each commit. Avoid staging unrelated files by accident.
   - Commit each group with a conventional commit subject.

5. Verify each meaningful slice.
   - Run focused tests for each slice when practical.
   - If Go tests fail because the default cache is outside the sandbox, rerun with `GOCACHE` inside the repository, e.g. PowerShell: `$env:GOCACHE="$PWD\.gocache"; go test ...`.
   - If golden tests fail only due CRLF/LF representation after checkout, report it specifically and avoid modifying restored backup content unless the user wants newline normalization.
   - Remove temporary local caches such as `.gocache` after tests.

6. Align with the backup.
   - After all split commits, compare the target branch to the backup branch:
     - `git diff --stat <target> <backup>`
     - `git rev-parse '<target>^{tree}'`
     - `git rev-parse '<backup>^{tree}'`
   - The tree hashes must match for exact alignment. An empty diff is helpful but tree hashes are the final check.
   - If the trees differ, inspect `git diff --name-status <target> <backup>`, restore missing pieces from the backup, commit or amend as appropriate, and repeat the tree-hash check.

## Guardrails

- Never use `git reset --hard`, `git checkout -- .`, or destructive cleanup unless the user explicitly asks.
- Preserve user changes. If an untracked or modified file appears unrelated, back it up if the user asked for "all changes".
- On Windows PowerShell, quote revision expressions that contain `^`, for example `git rev-parse 'main^{tree}'`.
- Branch names are path-like refs. A branch named `backup/foo` prevents creating a branch named exactly `backup`.
- Prefer explicit path staging for split commits. Use `git add -A` only for the initial all-changes backup or when the user explicitly wants everything.

## Final Response

Report:

- Backup branch and backup commit SHA.
- Split commits in order, with short SHAs and subjects.
- Whether the working tree is clean.
- The target and backup tree hashes when alignment succeeds.
- Any test commands run and any residual test caveats.
