Advanced Collaboration And Recovery

Advanced Git Concepts

Learn how experienced teams handle merge conflicts, rebase safely, and recover from production mistakes without losing auditability.

How to use this page: read each workflow, then run the commands in the interactive console and verify the graph changes.

Conflict And History Concepts

Merge Conflict

Happens when Git cannot automatically combine overlapping edits from two branches.

Conflict Markers

Files show <<<<<<<, =======, and >>>>>>> blocks to resolve manually.

Rebase Conflict

Occurs while replaying commits onto a new base. Resolve each commit, then continue rebase.

Cherry-pick

Applies one specific commit to another branch, useful for urgent hotfix back-ports.

Revert vs Reset

revert adds a safe undo commit for shared history. reset rewrites local branch history.

Force Push Discipline

Use --force-with-lease only on agreed branches and never on protected production branches.

Merge Conflict Resolution Workflow

  1. 1 Update your branch before opening or updating a PR.
    git checkout feature/cart && git fetch origin && git merge origin/main
  2. 2 Resolve conflict markers in changed files and keep intended logic.
    edit files with conflict markers then run tests
  3. 3 Stage resolved files and complete merge commit.
    git add . && git commit -m "merge: resolve conflicts with main"
  4. 4 Push and rerun CI checks before merge approval.
    git push origin feature/cart

Rebase Conflict Workflow

  1. 1 Start rebase onto latest mainline.
    git checkout feature/cart && git fetch origin && git rebase origin/main
  2. 2 Resolve each conflict, then continue rebase sequence.
    git add <resolved-file> && git rebase --continue
  3. 3 Abort if the branch becomes risky to untangle.
    git rebase --abort
  4. 4 Publish rewritten history safely.
    git push --force-with-lease origin feature/cart

Rollback Decision Matrix

Situation Recommended command Reason
Bad commit already shared git revert <sha> Preserves audit trail and avoids rewriting teammates' history.
Local commit not pushed yet git reset --soft HEAD~1 Allows editing commit before sharing while keeping file changes staged.
Hotfix must also reach release branch git cherry-pick <sha> Moves one proven fix without merging unrelated commits.
Emergency production rollback git revert <sha> + redeploy pipeline Fast, traceable rollback that fits regulated release controls.