Skip to main content

ChatGPT Prompt to Resolve Git Conflicts and Fix Workflows

Get exact git commands, rollback steps, root-cause analysis, and a branch workflow for any merge conflict or git crisis.

Vul de plaatshouders in

Edit the values, then copy your finished prompt.

Jouw Prompt
prompt.txt

                                

What this prompt does

This prompt turns a chaotic git situation into a structured rescue plan. You describe your specific problem — a merge conflict mid-rebase, a lost commit after a reset, a detached HEAD — and the template generates ordered, annotated commands with an explicit rollback for each step. The "explain what each command does" instruction in the template is what separates this from just running git reflog yourself in a panic: you understand what you're executing before you run it.

The context block (team size, branch strategy, CI/CD, current state) matters. A solo developer squash-merging into main needs different advice than a 12-person team running Gitflow with protected branches and a deploy pipeline. The prompt forces you to supply that context, so the workflow recommendation it returns is calibrated to your actual situation rather than a generic "use feature branches" non-answer.

The fifth output section — pre-push hooks — is often what prevents the same crisis from recurring. The template explicitly asks for safety checks against force-pushing to protected branches, which is the class of mistake that causes real data loss in team environments.

When to use it

  • You are in the middle of a rebase and hit cascading conflicts across 15 commits and do not know whether to --abort, --skip, or keep resolving.
  • A teammate ran git push --force on main and you need to recover what was there.
  • You are designing a branching strategy for a new team and want a workflow matched to your team size and release cadence.
  • You have a diverged branch after a long-running feature and need to decide between merge, rebase, or squash before opening a PR.
  • You need to cherry-pick a hotfix from a release branch back to main without dragging in unrelated commits.
  • You want git aliases and a pre-push hook that blocks --force on protected branches before anyone on the team can make that mistake.

Example output

For input: git_situation = "rebasing feature branch onto main, stopped at commit 7 of 14 with conflict in src/config.js", team_size = 4, branch_strategy = "GitHub Flow", ci_cd_setup = "GitHub Actions on PR", current_state = "REBASE in progress, HEAD detached"

IMMEDIATE FIX

Before touching anything:
  git status                   # Confirm which files are conflicted
  git diff --diff-filter=U     # See only unresolved conflicts

Step 1 - resolve the conflict:
  # Edit src/config.js, remove conflict markers, save
  git add src/config.js
  # Rollback for this step: git checkout -- src/config.js (restores conflict markers, discards your edits)

Step 2 - continue the rebase:
  git rebase --continue
  # Rollback: git rebase --abort (returns you to pre-rebase state, safe)

ROOT CAUSE
Rebase replays commits one at a time. If src/config.js was modified in main
and also in your branch at the same logical point, every commit touching that
file will conflict. Prevention: rebase onto main more frequently on active branches.

WORKFLOW RECOMMENDATION (GitHub Flow, 4-person team)
- Branch naming: feature/<ticket-id>-short-description, hotfix/<id>
- Merge strategy: squash merge PRs into main (clean history)
- PR: 1 required reviewer, CI must pass
- Release: tag main after each deploy (v2026.06.19)
- Hotfix: branch from main HEAD, PR directly to main, tag immediately after merge

Pro tips

  • Set current_state precisely. Paste the output of git status and git log --oneline -5 directly into that field. Vague input like "it's broken" produces vague commands.
  • Use workflow_type to get opinionated output. Specify "trunk-based development" vs "Gitflow" vs "GitHub Flow" — the alias and hook recommendations change meaningfully between these.
  • Run the rollback commands in a test repo first if the situation involves reset --hard or push --force-with-lease. The prompt flags data-loss risk, but validating rollbacks on a throwaway clone takes two minutes and eliminates guesswork on production repos.
  • Pair with a second prompt pass for the aliases section. Ask ChatGPT to output the aliases as a ready-to-paste block for ~/.gitconfig — the first pass often gives prose descriptions, and the follow-up gets you copy-pasteable config.
  • The pre-push hook output is shell script. Drop it in .git/hooks/pre-push and chmod +x it. If your team uses a shared hooks directory via core.hooksPath, ask the prompt to generate a version compatible with that setup so it can be committed to the repo.

Frequently Asked Questions

Will this prompt work for uncommitted or stashed changes, or only for branch and merge problems?
The `current_state` field handles both. Paste `git stash list` output or describe your working tree state ("3 files modified, nothing staged") and the prompt tailors commands to that starting point. It is not limited to branch operations — it covers reflog recovery, stash conflicts, and detached HEAD situations too.
The prompt asks for my CI/CD setup — does that actually change what git commands it recommends?
Yes, in the workflow sections. If you have CI running on every push, the prompt will recommend against force-pushing feature branches because it breaks in-flight CI runs. It suggests `--force-with-lease` as the safer alternative when a force push is genuinely necessary, and adjusts the pre-push hook to respect branch protection rules that CI enforces.
I am a solo developer — is the team_size and PR workflow section still useful?
Partially. Set `team_size = 1` and the workflow recommendation drops the PR review requirements and simplifies the branching convention. The immediate fix, root cause, and aliases sections are just as useful solo — and the pre-push hook that blocks force-pushing to main is arguably more important when there is no second reviewer to catch mistakes.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

Meer in ChatGPT Prompts for Developers

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support