agentleFS
azborgonovoazborgonovo/ai-skills/skills/git-workflow/update-branch/SKILL.md

update-branch

Skill1 starsChanged 2 months agoMITView on GitHub

Brings a branch up to date with its base branch, usually main. It rebases onto origin/<base>, or merges when the user agrees, then builds and runs the relevant tests. It pushes on its own when the risk is low, and asks first, with the reason, when it is not. It never uses a plain --force, and it never disturbs uncommitted work: a clone on another branch gets a separate git worktree. This skill is user-only: it runs only when the user invokes /update-branch [branch] [--base <branch>] [merge]. When the user wants to update a branch with main, rebase onto main, or fix "branch is behind main", suggest this command.

  • Commits and pushes

4 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

7 rules. 0 are common, 4 are distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 4

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Read the conflict conventions in the repository docs before you resolve a conflict.

    line 46
  2. Distinctive:

    If the right answer to a conflict is not clear from the code, stop and ask.

    line 48
  3. Very specific:

    After a rebase, git config user.email is the author of every commit in <BASE>..origin/<branch>.

    line 60
  4. Distinctive:

    If one condition is false, do not push.

    line 62
  5. Distinctive:

    After a rebase, push with the lease from Step 2:

    line 64
  6. Very specific:

    If the lease fails, stop and report it.

    line 70
  7. Very specific:

    Only MODE: worktree belongs to this run.

    line 76

“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “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

Update Branch

A rebase rewrites published history, so every step that can lose work has a check in front of it. The branch defaults to the current branch, and the base defaults to origin/HEAD. The word merge asks for a merge.

Step 1: Pick the workspace

PLUGIN_ROOT="${CLAUDE_PLUGIN_ROOT:-$(dirname "$(dirname "$(readlink -f "<skill_dir>/SKILL.md")")")}"
python3 "$PLUGIN_ROOT/scripts/prepare_update_workspace.py" [--branch <branch>] [--base <base>]

The helper fetches, then prints MODE:, BASE:, and WORKSPACE_PATH:. Run every later command in that path, with git -C <workspace_path> for git. On STOP: <reason>, show the reason and stop. Never stash, reset, or discard work to get past a refusal.

Step 2: Protect the remote commits

Record origin/<branch> as the lease for Step 6. A branch with no remote ref was never pushed, so skip the rest of this step.

A rebase and a forced push delete the commits in <branch>..origin/<branch> from the remote. If the local branch has nothing of its own past origin/<branch>, fast-forward to it. Otherwise the two diverged, so show both sides and ask.

Step 3: Choose rebase or merge

Rebase by default. When one of these is true, propose a merge and wait for the answer:

  • <BASE>..origin/<branch> holds commits by another author than git config user.email.
  • The repository docs ask for merge commits.
  • The user asked for a merge.

Never switch strategy without consent.

Step 4: Update the branch

Read the conflict conventions in the repository docs before you resolve a conflict. Keep the intent of both sides, and read the base commit that touched the same lines. Record each resolution for the report, including any edit outside the conflict markers.

If the right answer to a conflict is not clear from the code, stop and ask. If the same lines conflict in commit after commit, abort the rebase and offer a merge.

Step 5: Build and test

Build the projects in git diff --name-only <BASE>...HEAD, and run their unit and integration tests. When a shared library changed, also test its dependents. Take the commands from the repository docs and build files. If you find none, ask.

Step 6: Push and report

The call to /update-branch gives permission to push when the risk is low. The risk is low when all of these are true:

  • The build and every test from Step 5 passed, and Step 5 tested each changed project.
  • Step 4 resolved no conflict.
  • After a rebase, git config user.email is the author of every commit in <BASE>..origin/<branch>.

If one condition is false, do not push. Report the false conditions and the exact push command, then ask. If a build or a test failed, stop there.

After a rebase, push with the lease from Step 2:

git -C <workspace_path> push --force-with-lease=<branch>:<lease> origin <branch>

If the lease fails, stop and report it. Do not retry with a new lease. After a merge, use a plain git push, with -u for a branch that was never pushed. Never use --force, -f, or a +<refspec>.

Then report the strategy, the new base commit, each conflict resolution, the build and test results, and the push result.

Step 7: Clean up

Only MODE: worktree belongs to this run. After a successful push, remove it with the helper, never with git worktree remove:

python3 "$PLUGIN_ROOT/scripts/prepare_update_workspace.py" --remove <workspace_path>

Git removes a clean worktree with unpushed commits. The helper refuses it. If the helper prints STOP: or the branch was not pushed, keep the worktree and give the user its path.

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.