{"data":{"slug":"discovered-6c3a4d328b7a989a739afd0007c905db8dfcb1a7c393cf01","title":"Pull: Bring a branch up to date with its upstream when the tree may be dirty \u2014 fast-forward, moving aside only local edits that collide","summary":"Bring this branch up to date with its upstream when the tree may be dirty \u2014 fast-forward, moving aside only local edits that collide. This process ensures that local changes are preserved and conflicts are resolved appropriately.","url":"https:\/\/skillshunter.net\/skills\/discovered-6c3a4d328b7a989a739afd0007c905db8dfcb1a7c393cf01","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/discovered-6c3a4d328b7a989a739afd0007c905db8dfcb1a7c393cf01","markdown_url":"https:\/\/skillshunter.net\/skills\/discovered-6c3a4d328b7a989a739afd0007c905db8dfcb1a7c393cf01.md","download_url":"https:\/\/skillshunter.net\/skills\/discovered-6c3a4d328b7a989a739afd0007c905db8dfcb1a7c393cf01\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Before running the pull process, ensure that the branch has an upstream configured. If not, configure the upstream first. Also, ensure that any local changes are staged or resolved before proceeding with the pull.","instructions":"---\nname: pull\ndescription: >-\n  Bring this branch up to date with its upstream when the tree may be dirty \u2014 fast-forward, moving aside\n  only local edits that collide. TRIGGER when: asked to pull or sync, or a session on the other machine\n  asks for it after a push. DO NOT TRIGGER for a diverged branch or for committing.\nallowed-tools: AskUserQuestion, Read, Grep, Bash(git fetch:*), Bash(git rev-parse:*), Bash(git rev-list:*), Bash(git log:*), Bash(git diff:*), Bash(git status:*), Bash(git show:*), Bash(git ls-files:*), Bash(git cat-file:*), Bash(git stash:*), Bash(git merge:*), Bash(git add:*), Bash(git reset:*), Bash(python3 ~\/.claude\/skills\/shared\/session_clean.py:*), Bash(python ~\/.claude\/skills\/shared\/session_clean.py:*)\n---\n\n# Pull remote changes\n\nSync this branch with its upstream and settle whatever the sync turns up. A dirty tree is the normal case here, not an error \u2014 these repos are worked from two machines and often by several concurrent sessions \u2014 so the job is to move aside as little as possible, fast-forward, and put it back.\n\nRead `~\/.claude\/skills\/shared\/bash-rules.md` for bash command constraints.\n\nThe reference for every branch of the Process is `~\/.claude\/learnings\/git-stash-pull-safety.md`: it carries the recipes, the verification baselines, and the failure modes that produce no conflict at all. This file is the decision procedure, that one is the depth. Follow its section when a step names it rather than re-deriving a recipe it already holds.\n\n**When a message asked for this run** \u2014 every skill that pushes on the other machine sends one afterwards, `\/yolo`, `\/wrap-up`, `\/release` and `\/pr-merge` among them \u2014 the message is a claim, but this skill re-measures its premise in step 1: if nothing is inbound, say so and stop. Send no reply unless something needs the sender's attention; the `peer` skill covers anything the message asks beyond the pull.\n\n## Context\n- Fetch: !`git fetch -q 2>&1 || echo FETCH-FAILED`\n- Upstream: !`git rev-parse --abbrev-ref @{upstream} 2>\/dev\/null || echo NO-UPSTREAM`\n- Working tree status: !`git status --short`\n- Local changes vs HEAD: !`git diff --name-only HEAD`\n\n## Process\n\n1. **Measure the divergence, then settle the preconditions before touching anything.** Three inputs cannot come from the Context section, for two separate reasons, and both are recorded in `~\/.claude\/learnings\/skill-context-evaluator.md`. A `!` line whose command carries a revision range against `@{upstream}` is handed back to be run rather than preprocessed, while the same ref as a bare argument preprocesses fine. Worse, `!` lines are not evaluated in the order they are written, so any of them reading `@{upstream}` may see the ref as it stood *before* the Fetch line updated it. Nothing above is safe to read about the remote; a process step is, because every `!` line has finished by the time one runs. When this invocation was answered `Skill \/pull is already loaded above; instructions unchanged` rather than rendering the Context section, no Context line ran this time, so first run `git fetch || echo FETCH-FAILED`, `git status --short` and `git diff --name-only HEAD` yourself and use those as **Fetch**, **Working tree status** and **Local changes vs HEAD** (`skill-context-evaluator.md`, the section on a skill invoked again). Then run all three here, one per Bash call, and refer to their output by the names given:\n   ```\n   git rev-list --left-right --count @{upstream}...HEAD 2>\/dev\/null || echo NO-UPSTREAM\n   git log --oneline -n 40 HEAD..@{upstream} 2>\/dev\/null || echo NONE\n   git diff --name-status HEAD @{upstream} 2>\/dev\/null || echo NONE\n   ```\n   In order they are **Behind and ahead counts**, **Incoming commits** and **Incoming files**. Then stop wherever one of these holds:\n   - **Upstream** is `NO-UPSTREAM` \u2014 this branch tracks nothing. Say so, signal per step 10, and stop.\n   - **Fetch** is `FETCH-FAILED` \u2014 report its text verbatim and stop, because the three inputs this step measures are then stale. Do not signal: an unmeasured remote is a real thing to come back to.\n   - **Behind and ahead counts** reads `0` on the left \u2014 already current. Say so, signal per step 10, and stop. Do not stash, merge, or touch the tree to confirm it.\n\n2. **Read the reference before acting.** Normally that is `~\/.claude\/learnings\/git-stash-pull-safety.md` through the Read tool. When the repo being pulled *is* the dotfiles repo \u2014 it has `claude\/learnings\/` at its root \u2014 read the upstream copy instead, `git show @{upstream}:claude\/learnings\/git-stash-pull-safety.md`, because a behind checkout's documentation is behind by the same commits and this pull is what would fix it.\n\n3. **Classify the divergence** from **Behind and ahead counts** (left is behind, right is ahead).\n   - Behind only \u2014 the fast-forward path. Continue to step 4.\n   - Both non-zero \u2014 the branch has diverged and wants a rebase, which is not this skill's to run unasked. Show the incoming commits and the local ones and ask how to proceed. Stop on a no.\n\n4. **Work out what actually has to move.** Intersect the paths in **Local changes vs HEAD** with the paths in **Incoming files**. Git's refusal to fast-forward is per-path, so only the overlap is in the way.\n   - Empty intersection \u2014 stash nothing at all and go to step 6. This is the safer path, not merely the shorter one: another live session may be mid-edit in those files, and a stash\/pop lifts them off disk and back seconds later.\n   - Non-empty \u2014 stash exactly those paths in step 5, never the whole tree. Everything outside the overlap stays where it is.\n   - Check the untracked entries (`??` in **Working tree status**) against the `A` rows of **Incoming files**. An incoming commit adding a path that already exists untracked blocks the merge and is not covered by a stash; surface the collision and ask before moving that file.\n   - Before stashing, flag any overlapping file that the reference treats specially, and follow its section instead of the plain recipe: a file that is one enormous line (minified, single-line JSON, unwrapped prose) has no line granularity and must be re-applied rather than popped; a file the local side *deletes* while upstream modified it must be reconciled by content, because the modify\/delete conflict resolves cleanly while silently discarding upstream's addition.\n   - If **Incoming commits** shows 40 entries the list was capped there; say so before reasoning about completeness.\n\n5. **Stash only the paths step 4 named.**\n   ```\n   git stash push -m \"pre-pull local work\" -- <paths>\n   ```\n   Then record the baseline, which makes a later drop reversible and is what step 8 verifies against:\n   ```\n   git rev-parse stash@{0}\n   ```\n\n6. **Fast-forward.**\n   ```\n   git merge --ff-only @{upstream}\n   ```\n   A refusal here means step 4's intersection was wrong. Read the error and redo step 4 \u2014 never force, and never fall back to a merge commit.\n\n7. **Restore, keeping the staged\/unstaged split.**\n   ```\n   git stash pop --index\n   ```\n   Always `--index`: a plain pop flattens the split, destroying real information whenever the index held something deliberate. A conflicted pop **keeps** the stash entry, so resolve first, then `git add` the resolved paths, then `git reset -q` to return to an all-unstaged tree, and only then `git stash drop`.\n\n   With more than one conflict, triage the whole set before reading any of them \u2014 the reference's `awk` one-liner tags each half's headings, separating the mechanical both-appended case from two sides that rewrote the same material.\n\n8. **Verify, including the things that never conflict.** A clean merge is not evidence; these three checks are.\n   - Against the step 5 baseline, `git diff <stash-sha> -- .` should list exactly the incoming files, plus untracked files and any dirty paths deliberately left unstashed. Anything else is a local edit the merge mangled.\n   - For any document that merged, list its headings and read for two that mean the same thing. Two sessions adding the same knowledge in different places produces no conflict at all.\n   - Read the `A` rows of **Incoming files** against the existing filenames on the same subject \u2014 a pull that adds a file duplicating one already in the tree passes every other check.\n\n9. **Report**: how many commits came in and what they were, what moved aside and came back, what conflicted and how it was resolved, and anything left for the user to decide.\n\n10. **Say that this run left nothing to come back to**, where that is true, so the dashboard can rest the row instead of showing it as holding work:\n    ```\n    python3 ~\/.claude\/skills\/shared\/session_clean.py\n    ```\n    Use `python` on Windows. Run it when step 9's last two clauses are both empty \u2014 nothing conflicted and nothing is left for the user \u2014 or at whichever step 1 stop sent you here. Do **not** run it after a conflict you resolved or `FETCH-FAILED`, each of which is something to return to, and do not run it in a turn that ends on a question to the user. When the user's answer begins a turn that finishes the pull with nothing left, run it at the end of that turn: the dashboard counts the answer turn as part of the relayed exchange and settles the row CLEAN.\n\n    **The question that disqualifies it is the turn's, not the pull's.** Read those clauses against everything the turn goes on to do, because this skill is routinely nested: `\/wrap-up` step 2 sends a behind branch here, and its one summary approval then lands in the same turn; `\/yolo` step 1 sends one here too, and a hard stop later in that run asks in the same turn. A pull that settled cleanly inside a flow that is about to ask the user has left something to come back to, whatever the pull alone did \u2014 so skip the signal there rather than reading \"nothing is left for the user\" as scoped to steps 1 through 9. Measured 2026-10-01: a nested run posted at 00:15:07 and asked \"Shall I proceed?\" 46 seconds later; the dashboard refused the claim on its own status gate, which is a backstop and not a reason to send it.\n\n    Do not condition it on how the turn started, and do not condition it on what the row looked like beforehand. Both are the dashboard's to test and it holds the evidence for each: it recognises a relayed request by the fixed preamble it writes at the head of every relayed frame, and it knows what the row was before the relayed exchange began. Report what this run did and let it weigh the rest. The command prints nothing and always exits 0, including where no dashboard is listening \u2014 an absent signal is read as \"not clean\", which is the safe direction. A later prompt revokes a signal whose turn never settled, so a pull followed by real work needs nothing undone here.\n\n## Out of scope\n- Do NOT commit or push \u2014 that is `\/yolo` or `\/wrap-up`\n- Do NOT rebase a diverged branch without explicit approval; propose it and wait\n- Do NOT use `git pull --rebase --autostash` \u2014 its internal pop does not restore the index\n- Do NOT use `git checkout -- .` or any bare discard; the tree is dirty by premise\n- Do NOT drop a stash before step 8's checks pass\n","use_cases":["Synchronizing a local branch with its upstream when the working tree is dirty","Resolving conflicts between local changes and upstream commits","Ensuring that local edits are preserved during a pull operation"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/AnotherSava\/claude-code-common\/blob\/1a7f9f9cce53f6946ae1e3a9cc0733f2524a4b93\/claude\/skills\/pull\/SKILL.md","source_commit":"1a7f9f9cce53f6946ae1e3a9cc0733f2524a4b93","license":null,"version":null,"listing_approved_at":"2026-12-01","created_at":"2026-11-30T08:08:27.000000Z","updated_at":"2026-12-01T12:48:20.000000Z","seo_title":"Git Pull: Update Branch with Upstream Changes","seo_description":"A structured approach to pulling changes from an upstream branch while preserving local edits and resolving conflicts appropriately.","seo_keywords":["git pull","branch synchronization","upstream changes","conflict resolution","git workflow"]}}