Conflict Resolution
Resolving conflicts means reading both sides, picking what should survive, deleting the markers, then git add the file and committing to complete the merge.
Introduction
Resolving conflicts means reading both sides, picking what should survive, deleting the markers, then git add the file and committing to complete the merge.
Beginner analogy: think of Git as a "save game" system for your code — every commit is a checkpoint you can revisit, branches are alternate timelines you can explore safely, and a remote like GitHub is the cloud save your whole team can sync with.
In this lesson we will walk through Conflict Resolution step by step, connect the command to Git's internal model, practice a realistic team scenario, and learn the failure modes that matter in production repositories.
Purpose of this lesson
The goal is to make Conflict Resolution operationally useful: you should know when to apply it, which part of Git state it changes, how it affects teammates, and how to recover if the workflow goes wrong.
Understanding the topic
Use this as a foundation for daily version control. The important mental model is that Git tracks snapshots through a content-addressed history, while your working tree, staging area, local branch, and remote branch can all be at different states.
Core concepts to understand:
- Clear definition and mental model of conflict resolution, including which Git layer it changes.
- How the working tree, staging area, local repository, branch refs, and remote refs can differ at the same time.
- How conflict resolution changes review, CI/CD, release notes, rollback, and team coordination.
- Safety nets:
reflog, rescue branches,revert,--force-with-lease, and protected branches. - Risk patterns: rewriting public history, committing secrets, resolving conflicts carelessly, and letting branches drift for weeks.
- Production context: what this looks like in a repository with required reviews, CI gates, release tags, and audit logs.
Visual explanation
Use this architecture view to reason about where the change lives:
Developer Code Changes|vWorking Directory|vgit add -> Staging Area|vgit commit -> Local Repository|vgit push -> Remote Repository|vTeam Collaboration
git merge feature/loginGit tries to auto-merge both branches.
Step-by-step explanation
- Start from a clean working tree and update
mainwithgit fetchplus your team's preferred pull or rebase policy. - Create a short-lived topic branch with a name that communicates intent, such as
feature/payment-retryorfix/null-session. - Commit in small reviewable slices; use
git diff --stagedbefore each commit to verify the snapshot. - Integrate with the target branch using merge or rebase based on team policy, resolving conflicts by preserving behavior rather than blindly choosing one side.
- Push with an upstream branch, open a PR, let CI validate the result, and delete the branch after merge.
Syntax reference
Visual workflow / architecture:
Developer Code Changes|vWorking Directory|vgit add -> Staging Area|vgit commit -> Local Repository|vgit push -> Remote Repository|vTeam Collaboration
Informative example
Hands-on commands you can copy-paste:
git add moves changes from your working directory into the staging area. git commit snapshots that staging area into your local repository with a unique SHA hash and a message.
# Stage changesecho "# My Project" > README.mdgit add README.mdgit status# Commit themgit commit -m "feat: add README"
Sample terminal output:
On branch mainChanges to be committed:new file: README.md[main (root-commit) e7c1a2b] feat: add README1 file changed, 1 insertion(+)create mode 100644 README.md
Walk-through: notice how Git always prints what changed and where the new state lives — in the working directory, staging area, local .git store, or on the remote. Reading these messages carefully is the difference between a senior Git user and a junior one who fights the tool.
Real-world use
A product team keeps main deployable while several engineers work in parallel. One developer uses Conflict Resolution to isolate a change, explain the intent, verify behavior in CI, and leave behind history that is useful during review, debugging, and release notes.
Enterprise use cases
In an enterprise repository, Conflict Resolution is supported by branch protection, CODEOWNERS, signed commits, required status checks, secret scanning, audit logs, and a documented rollback process. The professional standard is not "I know the command"; it is "the workflow is safe for hundreds of contributors and recoverable during an incident."
Best practices
- Write commit messages in the
type(scope): summaryConventional Commits style —feat(auth): add JWT refresh. - Pull (or rebase)
mainbefore starting any new work to avoid painful conflicts later. - Keep branches short-lived (under 2 days) and pull requests under 400 lines for fast reviews.
- Always use
--force-with-leaseinstead of--forcewhen pushing rewritten history. - Never commit secrets, build artifacts,
.envfiles ornode_modules— add them to.gitignore.
Common mistakes
- Force-pushing to a shared branch — wipes teammates' work and is hard to recover from.
- Committing huge binary files into Git — repository balloons forever; use Git LFS instead.
- Resolving a merge conflict by accepting all of one side without reading the other — silent regressions.
- Working directly on
main— bypasses code review and breaks the deployable contract.
Debugging tips
- Before resolving, run
git statusandgit diff --name-only --diff-filter=Uto see exactly which files are conflicted. - Use
git log --oneline --left-right --mergeduring merge conflicts to understand the competing commits. - If a rebase becomes confusing,
git rebase --abortreturns you to the pre-rebase state; do that before experimenting blindly.
Optimization strategies
- Make the common path boring: clear branch names, consistent commit messages, protected main, and predictable PR policy.
- Automate checks that humans forget: formatting, secret scanning, tests, signed commits, and branch protection.
- Use Git's safety nets intentionally, especially
reflog,revert, and--force-with-lease.
Advanced interview questions
Interview Prep
Practice concise answers, then expand each card for the explanation.
1QuestionExplain <strong>Conflict Resolution</strong> in one sentence as if to a junior teammate.+
Answer
2QuestionWhere does <strong>Conflict Resolution</strong> operate: working tree, staging area, local repository, remote, or hosting platform?+
Answer
3QuestionHow would you recover if <strong>Conflict Resolution</strong> goes wrong on a shared branch?+
Answer
git reflog and the remote state, prefer revert for shared history, and use --force-with-lease only when rewriting private branch history is expected.4QuestionWhat production safeguard would you add around <strong>Conflict Resolution</strong>?+
Answer
Hands-on exercise
Build a disposable lab for Conflict Resolution. Create a branch, make one intentional change, inspect the diff, commit it, then introduce one realistic mistake and recover. The exercise is complete only when you can explain which layer changed: working tree, index, local branch, remote branch, or object database.
Suggested lab directory: git-conflict-resolution-lab.
mkdir git-conflict-resolution-labcd git-conflict-resolution-labgit initgit switch -c practice/conflict-resolutionecho "first change" > notes.txtgit status -sbgit add notes.txtgit commit -m "practice: explore conflict-resolution"git log --oneline --graph --decorate --all
Summary
Conflict Resolution is valuable when it makes history easier to understand, collaboration safer, and recovery faster. Treat Git as both a local database and a team operating system: inspect state before changing it, keep history useful, and automate the rules that protect production.