Branches let you work in parallel — but real projects get messy. You need to switch tasks mid-edit, combine branches that touched the same lines, or copy one specific fix without merging everything. Three tools handle that: stash, conflict resolution, and cherry-pick.

Git Stash — Pause Your Work

You're halfway through a CSS refactor on feature/new-nav when production breaks on main. You need to switch branches now, but your changes aren't ready to commit.

Stash saves your uncommitted work to a temporary shelf and restores a clean working tree.

git stash

Git responds with something like Saved working directory and index state WIP on feature/new-nav.

Your modified files revert to the last commit. You can switch branches safely:

git switch main
# fix the bug, commit, push...
git switch feature/new-nav
git stash pop

git stash pop reapplies your shelved changes and removes them from the stash list.

Useful Stash Commands

# List all stashes
git stash list

# Stash with a label so you remember what it was
git stash push -m "WIP dark mode nav styles"

# Apply without removing from the stash list
git stash apply

# Drop a stash you don't need
git stash drop stash@{0}

# Clear all stashes
git stash clear

Stash is for temporary parking. If the work is meaningful, commit it on a branch instead. Stashes are easy to forget and don't get pushed to GitHub.

Merge Conflicts — When Git Can't Decide

A merge is smooth when branches changed different files or different parts of the same file. A conflict happens when both branches edited the same lines — Git doesn't know which version to keep.

Create a Conflict on Purpose

Start on main with this index.html:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>My Blog</title>
    <link rel="stylesheet" href="styles.css" />
  </head>
  <body>
    <h1>Welcome to My Blog</h1>
    <p>Thoughts on web development.</p>
  </body>
</html>

Commit it, then create two branches from the same point:

git switch -c feature/new-heading

Change the heading and commit:

<h1>Welcome to My Dev Blog</h1>
git add index.html
git commit -m "Update heading on feature branch"

Switch back to main and make a different heading change on the same line:

git switch main
<h1>Welcome to Fiaz's Blog</h1>
git add index.html
git commit -m "Update heading on main"

Now merge the feature branch:

git merge feature/new-heading

Git stops and reports a conflict:

Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.

Reading Conflict Markers

Open index.html. Git marked the problem area:

<<<<<<< HEAD
    <h1>Welcome to Fiaz's Blog</h1>
=======
    <h1>Welcome to My Dev Blog</h1>
>>>>>>> feature/new-heading
  • <<<<<<< HEAD — your current branch's version (main)
  • ======= — separator
  • >>>>>>> feature/new-heading — the incoming branch's version

You decide the final result. Edit the file to what you actually want — often a blend, sometimes one side wins:

    <h1>Welcome to Fiaz's Dev Blog</h1>

Delete all conflict markers (<<<<<<<, =======, >>>>>>>). Save the file.

Finish the Merge

git add index.html
git status

git status shows "All conflicts fixed but you are still merging." Complete it:

git commit -m "Merge feature/new-heading and resolve heading conflict"

No -m needed if you want — Git opens a default merge commit message.

Abort If You Need a Do-Over

git merge --abort

This cancels the merge and returns you to the state before you ran git merge.

Conflict Tips

  • Merge or pull often — small, frequent merges mean smaller conflicts.
  • Communicate — on teams, coordinate who edits which files.
  • Use git status — it lists every conflicted file.
  • Never commit conflict markers — if you see <<<<<<< in your editor, you're not done.

Pull requests on GitHub show the same conflicts. You resolve them locally or in GitHub's web editor, then commit.

Cherry-Pick — Grab One Commit

Sometimes you need one specific commit from another branch — not the whole branch. Cherry-pick copies a single commit onto your current branch.

Setup Example

On main, you have commits A → B → C. On feature/dark-mode you have A → B → D → E, where E is a small bug fix you want on main but you're not ready to merge the entire dark-mode feature.

Find the commit hash:

git log --oneline feature/dark-mode
a1b2c3d Add dark mode styles
d4e5f6g Fix contrast on link hover    ← you want this one

Switch to main and cherry-pick:

git switch main
git cherry-pick d4e5f6g

Git applies that commit's changes on top of main as a new commit (new hash, same changes). Dark mode CSS stays on the feature branch; only the link fix lands on main.

When Cherry-Pick Gets Conflicts

If main changed the same lines since that commit was made, cherry-pick can conflict — resolve it the same way as a merge: edit the file, remove markers, git add, then:

git cherry-pick --continue

To cancel:

git cherry-pick --abort

Cherry-Pick vs Merge

Situation Use
Bring an entire feature into main git merge
Copy one bug fix from a feature branch git cherry-pick
Undo a bad commit (advanced) git revert (different tool)

Cherry-pick is common for backporting fixes: a bug is fixed on main and you cherry-pick that commit onto a release branch.

Quick Reference

Command What it does
git stash Shelve uncommitted changes
git stash pop Restore shelved changes
git merge branch Combine branch (may conflict)
git merge --abort Cancel a conflicted merge
git cherry-pick HASH Apply one commit to current branch

These tools show up constantly in team workflows — especially stash when context-switching and conflict resolution during git pull and pull request merges. Next up: pushing your work to GitHub.