agentleFS
mDevsLabsmDevsLabs/Skills/skills/git-workflow-assistant/SKILL.md

git-workflow-assistant

Skill2 starsChanged 4 months agoMITView on GitHub

Guides Git operations safely — branching, rebasing, merge-conflict resolution, history rewriting, recovery of lost commits, bisecting bugs, and writing conventional commits and pull-request descriptions. Use when the user is stuck in a rebase or merge, wants to undo a commit, lost work, needs to clean up history before a PR, asks about reflog, cherry-pick, submodules, or how to write a commit message or changelog.

  • Reads credentials
  • Deletes or force-pushes
  • Installs packages
  • Commits and pushes

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 3 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    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
  • could be automatic: a setting could enforce it
  1. Very specific:

    Never suggest git push --force: Use --force-with-lease, always.

    line 32
  2. Distinctive:

    Warn explicitly: before anything that rewrites shared history or discards uncommitted changes, and say precisely what will be lost.

    line 33
  3. Distinctive:

    If the work was never committed, Git cannot help.

    line 71
  4. Very specific:

    Verify: build and run tests before git add and --continue.

    line 80
  5. Distinctive:

    Default recommendation: trunk-based, branches under 2 days, squash-merge to keep main linear and revertible.

    line 137

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Git Workflow Assistant

Get the user unstuck without destroying work. Git rarely loses commits — people lose pointers to them.

When to use

Any Git question, especially the scary ones: "I think I deleted my work", "my rebase is broken", "I committed a secret", "I need to undo a push".

Hard rules

  1. Ask what state the repo is in before advising. Request git status && git log --oneline -10 && git branch -vv — a wrong assumption here costs the user their work.
  2. Create a safety net before any destructive command: git branch backup/$(date +%Y%m%d-%H%M%S).
  3. Never suggest git push --force. Use --force-with-lease, always.
  4. Warn explicitly before anything that rewrites shared history or discards uncommitted changes, and say precisely what will be lost.
  5. Committed work is recoverable for ~90 days via reflog. Say this first when someone panics — then recover it.

Decision table: "I want to undo…"

GoalCommandDestructive?
Unstage a filegit restore --staged <file>No
Discard uncommitted changes to a filegit restore <file>Yes — unrecoverable
Amend the last commit messagegit commit --amendRewrites history if pushed
Add a forgotten file to the last commitgit add f && git commit --amend --no-editSame
Undo the last commit, keep changes stagedgit reset --soft HEAD~1No
Undo the last commit, keep changes unstagedgit reset HEAD~1No
Undo the last commit, delete the changesgit reset --hard HEAD~1Yes — reflog can recover the commit
Undo a pushed commitgit revert <sha>No — safest option on shared branches
Undo a pushed mergegit revert -m 1 <merge-sha>No
Drop a commit from the middlegit rebase -i <sha>~1, delete the lineRewrites history
Move commits to another branchgit cherry-pick <sha>… then reset the sourceRewrites the source
Recover a deleted branchgit reflog → git branch <name> <sha>No
Recover from a bad rebasegit reflog → git reset --hard HEAD@{n}Restores the pre-rebase state
Abort mid-operationgit rebase --abort / git merge --abort / git cherry-pick --abortNo
Stash including untrackedgit stash push -u -m "wip"No
Find which commit broke somethinggit bisect start / bad / goodNo
Find who changed a linegit log -L <start>,<end>:<file> or git blame -w -CNo

Recovering lost work

git reflog --date=iso | head -40          # every HEAD position, ~90 days
git fsck --lost-found                      # dangling commits and blobs
git stash list                             # stashes are easy to forget
git reflog show <branch>                   # per-branch history

Then: git branch recovered <sha> — inspect before resetting anything.

If the work was never committed, Git cannot help. Check the editor's local history (JetBrains "Local History", VS Code timeline) and say so honestly.

Merge conflicts

  1. git status — list conflicted files; understand why both sides changed.
  2. Resolve per file. Never blindly --ours/--theirs on a file you have not read.
  3. Reuse recorded resolutions on repeats: git config rerere.enabled true.
  4. For a 3-way view: git checkout --conflict=diff3 <file> shows the common ancestor.
  5. Verify: build and run tests before git add and --continue.
  6. During a rebase, "ours" and "theirs" are inverted relative to a merge — --ours is the upstream branch. State this explicitly; it causes real damage.

Reduce conflicts structurally: smaller PRs, rebase on the target branch daily, agree on formatter config, and add a .gitattributes merge=union for changelogs.

Committed a secret

Rotating the credential is step one and is non-negotiable — assume it is compromised the moment it is pushed. Then rewrite history:

pip install git-filter-repo
git filter-repo --invert-paths --path secrets.env      # or --replace-text
git push --force-with-lease --all
git push --force-with-lease --tags

Then: everyone re-clones (do not merge old clones back), and ask the host to expire cached views of the old objects. git rm alone does not remove it from history.

Commit messages and PRs

Conventional Commits:

<type>(<scope>): <imperative summary, <= 72 chars>

Why this change is needed, and what the reader cannot infer from the diff.

BREAKING CHANGE: <what breaks and how to migrate>
Refs: #123

Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert.

Rules: imperative mood ("add", not "added"); explain why, the diff already shows what; one logical change per commit; never "fix stuff" or "wip" on main.

Generate a message from the staged diff:

git diff --cached | python3 scripts/commit_helper.py --style conventional

Branching models

ModelFitsCost
Trunk-based + short-lived branchesContinuous deployment, strong CIRequires feature flags
GitHub FlowWeb apps, one production versionWeak for multiple supported releases
Git FlowVersioned/on-prem releasesHeavy; frequent merge pain
Release branches off trunkMobile, SDKsBackport discipline needed

Default recommendation: trunk-based, branches under 2 days, squash-merge to keep main linear and revertible.

Worked example

"I rebased onto main and now my last three commits are gone."

Step 1 — reassure and snapshot

git reflog --date=iso | head -20
a1b2c3d HEAD@{0}: rebase (finish): returning to refs/heads/feature
9f8e7d6 HEAD@{4}: commit: add retry logic     <- the work

Step 2 — recover without touching the current branch

git branch recovered 9f8e7d6
git log --oneline main..recovered      # confirm the three commits are there

Step 3 — reapply

git checkout feature
git cherry-pick <sha1> <sha2> <sha3>   # or: git reset --hard recovered

Cause: the rebase hit a conflict, and git rebase --skip was used instead of resolving — skipping drops the commit. Next time use --abort when unsure.

Quality checklist

  • Current repo state established before advising
  • Backup branch created before any destructive command
  • --force-with-lease used, never bare --force
  • Every command explained in one line, so the user learns
  • Consequences for collaborators on shared branches stated
  • Recovery path given for anything irreversible
  • Secret exposure → rotation advised before history rewriting

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.