multi-session-git
Skill0 starsChanged 22 days agoMITView on GitHub
Safe git when several agent sessions, terminals or people share one repository - check which branch HEAD is really on before every commit, work in your own git worktree instead of switching branches, stage explicit files only, and prove after every push that your commit is on the remote branch. Use before any `git commit`, `git push`, `git checkout`/`switch`, `git stash`, `git reset` or `git add -A` in a repo another session may be using, when running parallel agents, and when the user says "commit this", "push it", "ship it", "another session is working here", "use a worktree", or a push "succeeded" but the change is missing.
- Reads credentials
- Deletes or force-pushes
- Commits and pushes
In this repository4 other files it gives its agents.
- permission-unblockSkill
- post-deploy-smokeSkill
- prove-its-liveSkill
- secret-guardSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 42
One writer per branch: If two sessions must touch the same branch, serialize: one commits and pushes, the other fetches and rebases before …
- Very specific: line 43
Pushed is not deployed: After a verified push, use prove-its-live before saying anything is live.
- Very specific: line 47
Commit landed on the wrong branch: note its SHA (git -C <repo> log -1), move to your own worktree on the right branch, git cherry-pick …
≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Git when sessions share a repo
Two sessions in one folder share one HEAD, one index and one working tree. When session B runs
git checkout feature-x, session A's next commit lands on feature-x, and A's git push origin main
prints success while pushing nothing. Then someone says "it's live". Every rule below exists to make that impossible.
Before every commit
node ${CLAUDE_SKILL_DIR}/git-guard.mjs preflight --repo /full/path/to/repo --branch <the branch you think you are on>${CLAUDE_SKILL_DIR} is this skill's folder. It prints the real branch, upstream distance, what is staged,
what is modified, and every worktree. Exit 1 = HEAD is not your branch, is detached, or your branch is checked
out in another worktree. Then do not commit here and do not checkout; move to your own worktree (below).
Rules
- Address the repo by path, never by
cd.git -C /full/path/to/repo status. Acdin one command is easy to lose;-Cis explicit in every command and every log line. - Read the branch before you commit:
git -C <repo> rev-parse --abbrev-ref HEAD, or the preflight above. If it is not the branch you started on, someone else moved it. - Never
checkout/switcha shared folder to another branch, and never check out someone else's branch to "take a look". Usegit -C <repo> show <branch>:<file>orgit -C <repo> log <branch>to read it. - Your own worktree for your own work:
Work, commit and push from that path. Remove it when merged:git -C /full/path/to/repo fetch origin git -C /full/path/to/repo worktree add -b <your-task> /full/path/to/repo-wt-<your-task> origin/maingit -C /full/path/to/repo worktree remove /full/path/to/repo-wt-<your-task>. - Stage explicit files only:
git -C <repo> add src/a.ts src/b.ts. Nevergit add -A,git add .orgit commit -a: they sweep in another session's half-done files, generated files, and.env. Checkgit -C <repo> diff --cached --statbefore committing. - Do not touch what is not yours: no
git stash,git reset --hard,git checkout -- <file>,git cleanon files you did not change. Modified files you did not touch belong to another session. - After every push, verify it landed:
It asks the server (node ${CLAUDE_SKILL_DIR}/git-guard.mjs verify-push --repo /full/path/to/repo --branch maingit ls-remote), not your local tracking ref, whether your commit is in the remote branch. Or by hand:git -C <repo> fetch origin && git -C <repo> log -1 origin/main. "Everything up-to-date" after a commit is a red flag, not a success. - Never force-push a shared branch (
main,production, a branch someone else pushed to). If a push is rejected, fetch and rebase your own commits; do not overwrite theirs. - One writer per branch. If two sessions must touch the same branch, serialize: one commits and pushes, the other fetches and rebases before its own commit.
- Pushed is not deployed. After a verified push, use
prove-its-livebefore saying anything is live.
When things already went wrong
- Commit landed on the wrong branch: note its SHA (
git -C <repo> log -1), move to your own worktree on the right branch,git cherry-pick <sha>, push, verify. Tell the user the commit is also on the other branch; do not rewrite that branch without asking its owner. - Push printed success but
verify-pushsays NOT on the remote: you pushed a different branch than the one holding your commit. Push the right one (git -C <repo> push origin <your-branch>), then verify again. - Unsure who owns a change: ask, do not discard.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

