Conflicts, stash and cherry-pick
Reading conflict markers, resolving without losing work, shelving changes mid-task, and copying single commits.
What a conflict actually is
Git merges line by line. A conflict means both sides changed overlapping lines and Git will not silently choose — which is the entire point.
<<<<<<< HEAD
const limit = 20;
=======
const limit = 50;
>>>>>>> feature/pagingEverything above ======= is your current branch; everything below comes from the branch being merged. Delete the markers and keep the correct result (or a genuine combination).
git status # shows which files are unmerged
git checkout --ours f # keep your side wholesale
git checkout --theirs f # keep their side wholesale
git add f # mark resolved
git merge --continue
git merge --abort # give up, return to pre-merge state--ours/--theirs for an entire file throws away the other side's work in that file. Prefer hand-editing unless you are certain.Stashing work in progress
git stash push -m 'half-done refactor'
git stash list
git stash pop # restore and drop
git stash apply # restore but keep the entry
git stash -u # include untracked filesUseful for switching branches with uncommitted work. Avoid long-lived stashes — they are easy to forget and painful to merge later.
Cherry-pick and bisect
git cherry-pick <sha> # copy one commit onto this branch
# find the commit that introduced a bug
git bisect start
git bisect bad
git bisect good v1.4.0
# test, then mark each step good/bad
git bisect resetCherry-pick copies changes but creates a new commit — fine for hotfixes across release branches, a maintenance burden if used as routine workflow.
FAQ
Why do conflicts keep recurring between branches?
Lost something in a stash?
git fsck --unreachable or check the reflog of the stash entry.Related
Branching and merging Undoing mistakes
Last refreshed 2026-09-17.