git
Local git: commit, push, worktree, base sync, rebase/squash/fixup, and history search (blame, bisect, log -S, reflog). Load before a task's first commit, push or worktree, or pass load_skills=['git']
SKILL.mdpackages/shared-skills/skills/git/SKILL.md
GitHubGit
Load this skill with the read tool, tool.read({ path }) inside a cell, or load_skills, because those paths apply the user's git settings and the bare prelude read(path) does not.
Local git: state, commits, worktrees, base sync, history rewrite, push, history questions. Anything on GitHub itself (pull requests, checks, issues, merging) is the github skill; hand it the head SHA you pushed.
Commit, push, rebase, reset, stash or delete only when the user asked for it or a workflow they started requires it (ulw-loop commits each verified unit; a PR workflow pushes its branch). An investigative ask ends with findings.
Running git from an eval cell
git stays the CLI you already know. The cell adds what a shell line lacks: a failure that stops the cell, reads that run together, and values that reach the next call. On a harness without a js cell the same rules hold for plain shell lines: git -C <repo> on every call, set -e or && between dependent steps.
const git = (repo, ...args) => Bun.$`git -C ${repo} ${args}`.quiet().text() // repo is an absolute path; a non-zero exit throws
const [state, head] = await Promise.all([git(R, "status", "--short", "--branch"), git(R, "rev-parse", "HEAD")])
- One cell answers one question. Every read it needs goes into one
Promise.all, and the results stay in variables for the step that uses them. Never spend a turn pergit status. - A failed step must stop what depends on it.
git()throws. In atool.bashscript that isset -eor&&;;is for independent reads, because after a failedfetchorcheckoutit runs the rest on the wrong commit and the cell still looks green. tool.bashis for shell syntax (pipes, globs, loops) and for a command that can run for minutes, such as a clone or a push whose hooks run tests. Give it the repo too:git -C <abs-path>orcwd; acddoes not carry to the next call.- A ref is usable only after this clone has it. Fetch the exact ref (
git fetch origin <branch>,refs/pull/<n>/head), thengit rev-parse --verify '<ref>^{commit}'before it is checked out, diffed or merged. A SHA from a message or another machine is not here until fetched. - Two git commands that write to one worktree never run at the same time: the second dies on
index.lock. - Keep output small:
--stator--name-onlyfirst, then the one file.
Reading state
status --short --branch gives the upstream and ahead/behind. symbolic-ref --short refs/remotes/origin/HEAD names the default branch, so never guess main or master. log -15 --format='%h %s' shows the message style. git diff A..B compares the two tips, including what A gained since they split; git diff A...B shows only B's side since the merge base.
Commits
- Message style comes from the log: language, casing, prefix. Conventional Commits only where the log uses them.
- One commit per behavior that could be reverted alone, with its tests. Generated files travel with the source that produced them.
- Stage the paths you name.
git add -A,git add .andcommit -aare for a worktree you created in which every change is yours; anywhere else they sweep in someone else's work. - Hooks run.
--no-verifyneeds the user's word. - Commit under the repository's configured identity. If none is configured, report it; never invent one with
-c user.name=. - Report hashes, subjects and what is still uncommitted.
Worktrees
- One task, one worktree on its own branch: fetch, then
git worktree add -b <branch> <path> origin/<base>. Readgit worktree listfirst; a branch checked out elsewhere cannot be checked out or force-moved here. - No
git stashwhere worktrees share a repository. The stash belongs to all of them, and astash popin the wrong one drops foreign changes into your tree. Park work as a commit on your branch. - Remove what you added (
git worktree remove <path>, then the branch) once its work is merged or abandoned.
Syncing with the base, rewriting, pushing
- Follow the repository's rule for merge versus rebase. Without one, merge the base into a branch that is already pushed and rebase only unpushed work.
- Preview first:
git merge-tree --write-tree --name-only HEAD origin/<base>exits 1 and lists the conflicted paths without touching the tree. - A merge that stops on a conflict exits 1, so
git()throws: catch that error alone, list the paths withgit diff --name-only --diff-filter=U, and resolve each by reading both sides. A generated file, bundle or lockfile is regenerated from the resolved sources, never picked with--oursor--theirs. - Never push while a merge or rebase is in progress. Before every push,
git statusshows no operation in progress and no unmerged paths, and the checks that passed ran on this exact HEAD. - Never rewrite
main,master,devor a release branch. On your own pushed branch use--force-with-lease, never--force. - Fixups:
git commit --fixup=<hash>, thenGIT_SEQUENCE_EDITOR=: git rebase -i --autosquash <base>. A rebase gone wrong:git rebase --abortfirst, reflog after. reset --hardandcleandestroy uncommitted work: run them only in a tree whosestatusyou just read.- After a push, read the head back and hand it on in the same cell:
const sha = (await git(R, "ls-remote", "origin",refs/heads/${branch})).slice(0, 40), then thegithubskill'spr.wait({ repo, number, headSha: sha })andpr.merge({ matchHeadSha: sha }). Never poll withsleep.
History questions
log -S (a string's count changed), log -G (a diff line matches), blame -L a,b -- file, log --follow -- file, bisect with a deterministic test and known good and bad commits, reflog for local movement. Answer with the commit hash, subject and path that prove it, and say what stays unproven.