🐍 Python for Everyone

← Back to the project

Chapter 28 — Solo → AI-Paired → Critique 25 min

Now Pair With an AI

Step 1: You already built this solo

You just worked through the Git Workflow Practice project yourself, unaided — branching, hitting a real conflict, resolving it, merging, and rebasing, all by hand in your terminal. That project is unchanged; this page is additive. Now imagine a messier, more realistic version of that same situation: a conflict you're stuck on mid-workflow, and you turn to an AI assistant for help getting unstuck — the way developers actually do this on real teams, constantly.

Step 2: Now pair with an AI

Here's a real prompt a learner could give an AI assistant while stuck exactly where Step 2 of the main project leaves you — mid-merge-conflict, wanting to move fast:

the-prompt.txt
I'm resolving a merge conflict in recipe.txt. My team's shared
"feature/double-recipe" branch has two commits on it that a
teammate already pushed and pulled down (we've both been
committing to it for a few days). I tried to merge it into main
and got a conflict on the "Serves:" line. I already have some
uncommitted local edits to recipe.txt that I made before I even
started the merge -- I don't remember exactly what they were.

I just want this done fast: how do I resolve the conflict, get
everything merged and pushed, and clean up my branch so the
history looks tidy for the pull request?

And here's a plausible response — the kind of advice an AI assistant might hand back on the first try, confident and procedurally correct-looking. Read it the way you'd read a teammate's Slack message talking you through a fix, before scrolling to the critique below.

ai-response.txt
No problem, here's the fastest path to a clean PR:

1. First, get rid of the noise so you're only looking at the
   real conflict:

     git checkout -- recipe.txt

   This clears your uncommitted local edits and leaves you with
   just the conflicted merge state to deal with -- one less thing
   to think about.

2. Since your branch's changes (doubling the recipe) are the ones
   that actually matter here, just take your side of the conflict
   and move on:

     git checkout --ours recipe.txt
     git add recipe.txt
     git commit -m "Merge feature/double-recipe"

3. Now clean up the branch history before your PR so it's tidy --
   squash everything into one commit and force-push it:

     git checkout feature/double-recipe
     git reset --soft main
     git commit -m "Double the chili recipe"
     git push --force origin feature/double-recipe

That gives you one clean commit on the branch and a resolved
merge on main. Ready for review!

It's confident, uses real commands correctly, and reads like exactly the kind of fast, decisive answer you asked for. It's also genuinely risky in three separate ways.

Step 3: Where did the AI's advice lie to you?

Click to see the critique

What it looks like it does: "clears the noise" so the merge conflict is easier to focus on — framed as a harmless cleanup step, something you'd do to simplify your own view of the problem.

What it actually risks: git checkout -- recipe.txt permanently discards uncommitted changes in the working directory, with no undo and no reflog entry — reflog only tracks where commits and HEAD have pointed, never uncommitted edits that were never staged or committed in the first place. The prompt explicitly said "I don't remember exactly what they were," which is precisely the situation where you cannot verify nothing important is being thrown away. A safe assistant treats "I don't remember what these changes are" as a reason to stash or diff first, not a reason to discard faster.

Why it matters: once uncommitted, unstashed work is discarded this way, it is gone — not "hard to find," genuinely unrecoverable. On a real team this is the single most common way people lose real work: a quick "clean this up first" step taken under time pressure, before anyone checked what was actually in it.

The fix: git stash push -m "pre-merge WIP" instead — it achieves the same "clean working directory" goal but keeps the changes recoverable on the stash stack, so they can be inspected or reapplied later once the merge is sorted out.

What it looks like it does: "take your side of the conflict" sounds like a reasonable simplification when you believe your branch's changes are the ones that matter.

What it actually risks: git checkout --ours recipe.txt doesn't just resolve the conflicted lines in your favor — it replaces the entire file with your branch's version, silently discarding every change main made to that file, including changes far from the conflicted lines that auto-merged cleanly and were never in dispute. In this scenario, main's "Clarify serving size" edit disappears entirely, with no warning, no conflict marker, nothing flagging that a decision was even made. Whether "just take our side" is the right call for the *conflicted lines* is a judgment call worth making deliberately; blowing away the *rest of the file* along with it is not something the person asking ever agreed to.

Why it matters: --ours/--theirs are whole-file operations, not per-line "pick a side" tools — a very easy thing to not realize until it's already cost someone their work. On a shared file, this is exactly how a teammate's real, intentional change quietly vanishes from a merge with nobody noticing until much later.

The fix: open the file, read both sides of each conflict block individually, and resolve deliberately — exactly what the main project's Step 4 walks through. If the intent really is "keep my whole file, discard theirs entirely," say so explicitly and treat it as a reviewed decision, not a default.

What it looks like it does: "clean up the branch history before your PR" sounds like good practice — squashing messy commits into one clean commit is a genuinely good habit (see the main project's "squash three messy commits" idea).

What it actually risks: the prompt says a teammate "already pushed and pulled down" commits on this exact branch — meaning it is shared, not private. git reset --soft main followed by a new commit rewrites those commits with new hashes, and git push --force overwrites the remote branch to match. The teammate's local copy now has commits that no longer exist on the remote at all; their next git pull either creates a confusing divergent-history mess or, worse, if they push back without noticing, can silently re-push and resurrect exactly the messy history this was meant to clean up — or overwrite work in the other direction. Squashing itself isn't the problem; doing it to already-shared history via a bare force push, with no warning that this specifically breaks for a teammate who has the old commits, is.

Why it matters: this is the single most damaging git mistake a team can make, and it's damaging precisely because the person who runs the command doesn't see the damage — it lands on the teammate's machine, often hours later, as a confusing mess they now have to untangle.

The fix: either don't rewrite a shared branch's history at all (merge is always safe for shared branches), or if the team genuinely wants it cleaned up, coordinate first and use git push --force-with-lease instead of a bare --force — it refuses the push if the remote has commits you haven't seen locally, catching the "someone else pushed in the meantime" case that a bare force push overwrites silently.

Step 4: Your entry for this chapter's playbook

Fill this in for yourself — it's not saved or sent anywhere, just yours to keep (copy it into your own notes before you close this tab).

← Back to the Project All Chapters →