This lesson combines 3 topics: Workflow Models — Choosing the Right Strategy for Your Team, Pull Requests, Code Review and Interactive Rebase, Advanced Conflict Resolution.
Learning Objectives
- Understand Git Flow, GitHub Flow, GitLab Flow, Trunk-based Development
- Know which workflow to choose based on team size and release cadence
- Compare the trade-offs of each workflow
- Understand Pull Request (PR) culture and code review best practices
- Practice
git rebase -i(interactive rebase): squash, fixup, edit, reword - Use the
--fixupand--autosquashworkflow - Create atomic PRs that are easy to review
- Handle conflicts in large merges
- Understand semantic conflicts (the most dangerous kind)
- Use
git mergetool(kdiff3, VS Code) - Configure and use
git rerereto reuse conflict resolutions - The
--no-ffstrategy in team workflows
Part 1: Workflow Models — Choosing the Right Strategy for Your Team
1. Why choose a workflow?
Git lets you do many things, but the team needs to agree on one workflow. There is no single correct workflow — each one is optimized for a different context.
Questions to answer when choosing:
1. Release cadence: release several times a day or every few weeks?
2. Team size: 2 people or 50 people?
3. Versioning: do you support multiple versions in parallel?
4. CI/CD maturity: automated testing and deployment?
5. Hotfix policy: do you need quick prod fixes without a full deploy?
2. Git Flow (Vincent Driessen, 2010)
Branch structure
Main branches
| Branch | Role | Lifetime |
|---|---|---|
main | Production code, always deployable | Permanent |
develop | Integration branch, next release | Permanent |
feature/* | New features | Temporary |
release/* | Release preparation, bug fixes only | Temporary |
hotfix/* | Urgent production fixes | Temporary |
Git Flow lifecycle
# Feature development
git switch develop
git switch -c feature/user-notifications
# ... work ...
git switch develop
git merge --no-ff feature/user-notifications
git branch -d feature/user-notifications
# Prepare a release
git switch develop
git switch -c release/1.4.0
# Only bug fixes on the release branch, NO new features
git switch main
git merge --no-ff release/1.4.0
git tag -a v1.4.0 -m "Release version 1.4.0"
git switch develop
git merge --no-ff release/1.4.0 # merge the bug fixes back into develop
git branch -d release/1.4.0
# Hotfix on production
git switch main
git switch -c hotfix/payment-null-deref
# ... fix ...
git switch main
git merge --no-ff hotfix/payment-null-deref
git tag -a v1.4.1
git switch develop
git merge --no-ff hotfix/payment-null-deref # don't forget to merge into develop
git branch -d hotfix/payment-null-deref
When to use Git Flow
Good fit:
✓ Scheduled releases (every sprint, every month)
✓ Supporting multiple versions in parallel (v1.x, v2.x)
✓ Desktop apps, mobile apps, libraries (lib/SDK)
✓ Large teams that need tight control
Poor fit:
✗ Web apps with continuous deployment (CD)
✗ Small teams (<5 people) — too much overhead
✗ Startups that need to move fast
3. GitHub Flow (GitHub, 2011)
A much simpler workflow. There is only main and feature branches.
Core principles
1. main is always deployable
2. Everything is done on its own branch
3. Push often, open PRs early
4. Review on the PR
5. Deploy from the branch (test) before merging
6. Merge into main → deploy to production immediately
GitHub Flow lifecycle
# Full GitHub Flow cycle
git switch main && git pull
git switch -c feature/search-autocomplete
# ... work, commit many times ...
git push -u origin feature/search-autocomplete
# Open a PR on GitHub → review → CI runs
# Deploy the feature branch to staging for testing
# After approval
# → Merge the PR (squash or merge commit)
# → main is automatically deployed to production
# Local cleanup
git switch main && git pull
git branch -d feature/search-autocomplete
When to use GitHub Flow
Good fit:
✓ Web apps with Continuous Deployment
✓ Small to medium teams (2-20 people)
✓ Startups, SaaS
✓ When main always reflects production
Poor fit:
✗ Need to maintain multiple versions
✗ Releases have deployment windows (maintenance window)
✗ Regulatory compliance requires long testing phases
4. GitLab Flow
GitLab Flow is a middle ground: as simple as GitHub Flow but with additional environment branches.
With environment branches
With release branches (when you need versioning)
# There is no separate develop branch
# Feature → main → cherry-pick or merge into release branches
# Create a release branch when needed
git switch main
git switch -c release/2.3
# Hotfix: fix on main first
git switch main
git commit -m "fix: critical security patch"
# Backport to the release
git switch release/2.3
git cherry-pick <hash-of-fix>
5. Trunk-Based Development (TBD)
Everyone commits directly to main (the trunk) instead of using long-lived branches.
Two variants
Requirements for TBD to work
Mandatory:
✓ Feature flags (feature toggles) — turn off incomplete features in production
✓ Very strong CI/CD: tests run < 10 minutes, pass → auto deploy
✓ Pair programming or fast code review
✓ Branches live < 1-2 days
Supporting techniques:
- Branch by abstraction (large refactors without locking a branch)
- Strangler fig pattern (gradual migration)
# Feature flag pattern with TBD
// config/features.ts
export const FEATURES = {
newSearchAlgorithm: process.env.FEATURE_NEW_SEARCH === 'true',
betaPaymentFlow: process.env.FEATURE_BETA_PAYMENT === 'true',
};
// In the code
if (FEATURES.newSearchAlgorithm) {
return searchV2(query); // code incomplete, disabled by flag
}
return searchV1(query); // always runs in production
When to use TBD
Good fit:
✓ Google, Facebook, Netflix scale (mature CI/CD)
✓ Highly experienced teams
✓ Microservices with independent deploys
✓ Web services deploying many times a day
Poor fit:
✗ Teams without good CI/CD yet
✗ Outsourced development with contributors of uneven quality
✗ Need to maintain multiple versions
6. Overall comparison
| Criterion | Git Flow | GitHub Flow | GitLab Flow | Trunk-Based |
|---|---|---|---|---|
| Complexity | High | Low | Medium | Low–Medium |
| Long-lived branches | develop, release, hotfix | None | staging, production | None |
| Release cadence | Scheduled | Continuous | Flexible | Continuous |
| Versioning | Good | Poor | Good | Feature flags |
| Suitable team size | Large | Small-Medium | Any size | Experienced |
| CI/CD requirement | Low | Medium | Medium | High |
Quick decision tree
Part 2: Pull Requests, Code Review and Interactive Rebase
1. Pull Request — More than a merge request
A PR (or MR in GitLab) is the mechanism for proposing a code merge. It isn't just technical — it's communication.
Anatomy of a good PR
Title: feat(auth): add JWT refresh token endpoint
Description:
## Problem
Tokens expire after 1 hour, so users get logged out abruptly.
## Solution
Add a POST /auth/refresh endpoint that accepts a refresh token
and returns a new access token. The refresh token has a 7-day TTL.
## Changes
- src/auth/refresh.ts: new endpoint
- src/auth/middleware.ts: update token validation
- tests/auth.test.ts: add tests
## Test
- [ ] Unit tests pass (npm test)
- [ ] Manual test: login → wait > 1h → request with expired token
→ call /auth/refresh → receive new token → request succeeds again
- [ ] Test case: expired refresh token → 401
## Screenshots (if there is a UI change)
Closes #123
Atomic PR — Rule number 1
Each PR should:
- Solve one problem or one feature
- Be reviewable in < 30 minutes
- Be independently deployable (not depend on other unmerged PRs)
BAD — one PR that is too large:
"feat: redesign entire user module"
→ 50 files changed, 2000 lines
GOOD — split it up:
PR 1: "feat(user): add avatar upload endpoint"
PR 2: "feat(user): update profile page to show avatar"
PR 3: "feat(user): add avatar crop UI"
2. Code Review — Culture
Reviewer: The reviewing mindset
Ask, don't judge:
BAD: "This code is wrong"
GOOD: "I understand the intent, but what about edge case X?"
Suggest, don't command:
BAD: "Change it to a for loop"
GOOD: "Could we use .map() here? It looks more idiomatic — nit"
Label severity:
[blocker]: Security issue, logic bug — must fix
[major]: Code quality, maintainability — should fix
[minor]: Style, naming — nice to have
[nit]: Nitpick — author's call
[question]: I don't understand, please explain
Approve when:
- No unresolved blocker/major comments remain
- The code does what the PR title says
Author: The mindset when receiving review
- Comments are about the code, not about you
- Explain your reasoning (in a comment or the commit message) when you disagree
- Don't be defensive — reviewers often see what you missed
- Mark as "resolved" once you've fixed or explained it
3. Interactive Rebase — Cleaning up history
git rebase -i (interactive) lets you edit, combine, delete and reorder commits before pushing or opening a PR.
Basic syntax
# Interactive rebase of the N most recent commits
git rebase -i HEAD~3 # edit the 3 most recent commits
git rebase -i HEAD~5 # edit the 5 most recent commits
# Rebase from the point where you diverged from main
git rebase -i main
The editor that opens
# After git rebase -i HEAD~4, the editor shows:
pick abc1234 feat: add login form
pick def5678 fix: typo in button text
pick 9a8b7c6 WIP: still working on validation
pick 1f2e3d4 feat: complete login validation
# Commands:
# p, pick = use this commit
# r, reword = use the commit but change its message
# e, edit = use the commit but stop to amend it
# s, squash = combine into the previous commit, keep the message
# f, fixup = combine into the previous commit, discard this message
# d, drop = remove this commit
# Top-to-bottom order = oldest to newest
Common operations
squash — Combine commits, merge messages
Before:
pick abc1234 feat: add login form
squash def5678 fix: typo in button text
squash 9a8b7c6 WIP: still working
pick 1f2e3d4 feat: complete validation
→ Git combines abc+def+9a8 into one commit
→ Opens the editor so you can write a new message
fixup — Combine commits, discard the extra messages
pick abc1234 feat: add login form
fixup def5678 fix: typo in button text ← this message is discarded
fixup 9a8b7c6 WIP ← this message is discarded
→ A single commit with the message "feat: add login form"
reword — Only change the commit message
reword abc1234 feat: add login form ← change the message
pick def5678 feat: add logout
→ Git stops at abc1234 and opens the editor to change the message
→ The rebase continues automatically
drop — Delete a commit
pick abc1234 feat: add feature A
drop def5678 WIP: debug logging ← removed entirely
pick 9a8b7c6 feat: add feature B
→ commit def5678 no longer exists in the history
edit — Split one commit into several
# In the editor
edit abc1234 feat: add authentication and authorization
# Git stops at that commit
git reset HEAD~1 # unstage but keep the file changes
# Now you have 2 groups of changes in the working dir
git add src/auth/login.ts
git commit -m "feat(auth): add login logic"
git add src/auth/rbac.ts
git commit -m "feat(auth): add role-based access control"
git rebase --continue # continue the rebase
4. The --fixup and --autosquash Workflow
This is a very efficient workflow: instead of a manual rebase -i, you create fixup commits and --autosquash arranges them for you.
# Current history:
git log --oneline
# abc1234 feat: add login form
# def5678 feat: add user profile page
# You spot a typo in the login form, create a fixup commit
git add src/auth/login.ts
git commit --fixup abc1234
# → Automatically creates the message "fixup! feat: add login form"
# Another fix for the profile
git add src/profile/profile.tsx
git commit --fixup def5678
# The history now:
git log --oneline
# 7g8h9i0 fixup! feat: add user profile page
# 5e6f7g8 fixup! feat: add login form
# def5678 feat: add user profile page
# abc1234 feat: add login form
# Autosquash: automatically reorder and squash the fixup commits
git rebase -i --autosquash main
# The editor opens with the order already arranged:
# pick abc1234 feat: add login form
# fixup 5e6f7g8 fixup! feat: add login form
# pick def5678 feat: add user profile page
# fixup 7g8h9i0 fixup! feat: add user profile page
# Accept it and the rebase is done — clean history!
# Make autosquash the default (no need to type --autosquash every time)
git config --global rebase.autoSquash true
5. Real-world workflow: a feature PR with clean history
# 1. Create a feature branch from the latest main
git switch main && git pull
git switch -c feature/user-notifications
# 2. Work and commit freely (no need to be perfect)
git commit -m "WIP: notification component"
git commit -m "feat: add notification bell"
git commit -m "fix: typo"
git commit -m "feat: add notification count badge"
git commit -m "WIP: still need to handle click"
git commit -m "feat: complete notification dropdown"
git commit -m "test: add tests for notification"
# 3. Before opening the PR, clean up the history
git rebase -i main
# Squash the WIP commits into their related commits
# Desired result:
# pick a1 feat: add notification component with bell and badge
# pick a2 feat: add notification dropdown with click handler
# pick a3 test: add tests for notification component
# 4. Push (force-with-lease because you rebased)
git push -u origin feature/user-notifications
# Next time, if you add more fixups:
git push --force-with-lease
# 5. Open the PR → Review → Merge
Part 3: Advanced Conflict Resolution
1. Types of conflicts
Textual conflict — Git can detect it
Two people edit the same line or nearby regions of a file.
<<<<<<< HEAD
const MAX_RETRY = 3;
=======
const MAX_RETRY = 5;
>>>>>>> feature/retry-policy
Git can detect and report it — you just need to resolve it manually.
Semantic conflict — The most dangerous
The merge is "clean" (no textual conflict) but the logic is wrong.
// Developer A (main): renames the function
function processPayment(amount, currency) { ... }
// Developer B (feature/multi-currency): calls the function by its old name
const result = processOrder(amount); // TypeError at runtime!
The merge succeeds and CI passes if test coverage is low — but production crashes.
Prevention:
# Comprehensive tests after every merge
npm test && npm run e2e
# TypeScript/static analysis catches wrong function names
# Always run a type-check in CI:
tsc --noEmit
# Pair review: the reviewer reads the logic carefully, not just the diff
2. Handling conflicts in a large merge
Preview before merging
# See which files will conflict before merging
git merge --no-commit --no-ff feature/large-refactor
# if there are conflicts → git merge --abort to cancel
# if OK → git commit to finish
# To see diff3-style conflict markers (including the original) for a conflicted file:
git checkout --conflict=diff3 src/config.ts
# (enable diff3 by default: git config --global merge.conflictstyle diff3)
Strategy for large conflicts
# 1. Start the merge, git lists the conflicted files
git merge feature/big-feature
# CONFLICT (content): Merge conflict in src/api/routes.ts
# CONFLICT (content): Merge conflict in src/models/user.ts
# CONFLICT (add/add): Merge conflict in src/utils/validators.ts
# 2. List all conflicted files
git diff --name-only --diff-filter=U
# 3. Resolve one file at a time, starting with the one with the fewest dependencies
git add src/utils/validators.ts # resolved
git add src/models/user.ts # resolved
# ... continue ...
# 4. Check whether any files are still unresolved
git status | grep "both modified"
# 5. Complete the merge
git commit
# 6. IMPORTANT: run the tests right after the merge
npm test
3-way conflict markers (diff3 style)
# Enable the diff3 conflict style — see the common base
git config --global merge.conflictstyle diff3
# Output with diff3:
<<<<<<< HEAD
const timeout = 30000;
||||||| base ← content before either branch changed it
const timeout = 20000;
=======
const timeout = 60000;
>>>>>>> feature/auth
# Understand the context: base=20000, HEAD raised it to 30000, feature raised it to 60000
# Decide: maybe you need both → 90000? or just take feature = 60000?
3. git mergetool — Visual Conflict Resolution
# Run the mergetool (opens the configured editor)
git mergetool
# Or for a specific file
git mergetool src/api/routes.ts
Configuring VS Code as the mergetool
git config --global merge.tool vscode
git config --global mergetool.vscode.cmd 'code --wait $MERGED'
# Or use the VS Code built-in merge editor (Git 2.34+)
# VS Code automatically detects conflicts and shows a 3-way merge editor
Configuring vimdiff
git config --global merge.tool vimdiff
git config --global mergetool.vimdiff.layout "LOCAL,BASE,REMOTE/MERGED"
# LOCAL = HEAD (left)
# BASE = common ancestor
# REMOTE = the branch being merged
# MERGED = the output file (bottom)
Other popular tools
# Kdiff3 (GUI, cross-platform)
git config --global merge.tool kdiff3
# Meld (Linux, GUI)
git config --global merge.tool meld
# Beyond Compare (commercial, very powerful)
git config --global merge.tool bc
# IntelliJ/WebStorm have a built-in merge tool
4. git rerere — Reuse Recorded Resolution
rerere = Reuse Recorded Resolution. Git remembers how you resolved a specific conflict and automatically reapplies it if the same conflict appears again.
When is rerere useful?
Scenario: a long-running feature branch, frequently rebased onto main.
Every rebase hits the same conflict in the same file.
Without rerere: resolve manually every time → wasted time
With rerere: resolve the first time → Git remembers → applied automatically next time
Configuration and usage
# Enable rerere (resolutions are stored in .git/rr-cache/ in each repo)
git config --global rerere.enabled true
# Or only for the current repo
git config rerere.enabled true
# Workflow with rerere
# 1. First time you hit the conflict
git rebase main
# CONFLICT: src/config.ts
# Recorded preimage for 'src/config.ts'
# → rerere records the "image" of the conflict the first time
# Resolve manually
vim src/config.ts # edit the file
# Stage the file
git add src/config.ts
git rebase --continue
# → Git records: "this conflict" → "this resolution"
# 2. Next rebase (after main gets more commits)
git rebase main
# CONFLICT: src/config.ts
# Resolved 'src/config.ts' using previous resolution.
# → Git automatically fills the remembered resolution into the file
# (enable rerere.autoUpdate so Git also stages it: "Staged 'src/config.ts' using previous resolution.")
# Check that rerere applied it correctly
git diff src/config.ts # see the result
git add src/config.ts
git rebase --continue
# Show the recorded resolutions
git rerere status
# Show the details of a resolution
ls .git/rr-cache/
# Remove all rerere records (if you need to reset)
git rerere forget src/config.ts
# Automatically stage after rerere applies (careful — check first)
git config --global rerere.autoUpdate true
5. The --no-ff Strategy in Team Workflows
Why --no-ff matters in Git Flow
# Without --no-ff (fast-forward when possible):
# git log --graph:
# * abc1234 feat: add feature C (feature branch commit)
# * def5678 feat: add feature B
# * 9ab1234 chore: init
# → You can't tell where "feature C" ends or where it begins
# With --no-ff:
# * merge-hash Merge branch 'feature/C' into main
# |\
# | * abc1234 feat: complete feature C
# | * xyz1234 feat: WIP feature C
# |/
# * def5678 feat: add feature B
# → Clear: feature C consists of 2 commits, and you can see where it was merged
When to use --no-ff
# Git Flow: always --no-ff when merging a feature into develop
git switch develop
git merge --no-ff feature/user-search
git branch -d feature/user-search
# GitHub Flow: usually squash merge (GitHub UI) or merge commit
# → PR merge button: "Merge commit" vs "Squash and merge" vs "Rebase and merge"
# Squash merge: all the feature's commits become 1 commit
# → Very clean main history, but you lose the feature's detail
# → Suits teams that want main history = list of features
# Merge commit (--no-ff): keeps the structure
# → Suits audit trails and detailed debugging
6. Conflict Resolution Checklist
Before starting a large merge:
□ git status clean (no uncommitted changes)
□ git pull/rebase onto the latest main
□ Tell the team: "Merging X, hold off on merging to main"
While resolving:
□ Understand the context of both changes (read the commit messages)
□ Use the diff3 style to see the base
□ Test after each resolved file (don't wait until the end)
□ Note why you resolved it a particular way
After the merge:
□ git status clean (no conflict markers left)
□ Build passes: npm run build
□ Tests pass: npm test
□ Check for semantic conflicts (logic review)
□ Push with a PR so a reviewer can double-check
Review Questions
-
How many kinds of long-lived branches does Git Flow have? Name them and their roles.
Show answer
Git Flow has 2 long-lived branches:
main(production code, always deployable, tagged with versions) anddevelop(the integration branch where feature branches are merged, and the source for release branches). There are also 3 kinds of short-lived branches:feature/*,release/*,hotfix/*. -
Why does GitHub Flow require
mainto always be deployable?Show answer
GitHub Flow has no separate develop/staging branch —
mainis the only one and it deploys directly to production. Ifmainisn't deployable, no hotfix can be deployed immediately. This requirement forces the team to: (1) only merge PRs after CI passes and code review approves, (2) deploy from the branch before merging, (3) maintain a culture of "always green main". -
What problem do feature flags in TBD solve that branching cannot?
Show answer
Feature flags let you deploy the code of an unfinished feature to production without turning it on for users — the code exists in the codebase but is disabled. Branching can't solve this because a long-lived feature branch eventually has to be merged, and the longer it lives the more conflicts it accumulates. Feature flags separate "deploy" from "release" — the team can deploy frequently (TBD) without worrying about exposing incomplete features.
-
Which workflow should a SaaS startup with 5 developers deploying 3 times a day use? Why?
Show answer
GitHub Flow is the best choice. Reasons: (1) Small team — no need for Git Flow's overhead (develop, release branches). (2) Continuous deployment (CD) — GitHub Flow is designed for Continuous Deployment from
main. (3) Simple — fewer branches = less cognitive overhead = move fast. (4) If CI/CD matures further and the team wants it, they can migrate to Trunk-based Development. -
When should you choose GitLab Flow over Git Flow?
Show answer
GitLab Flow fits when: (1) You need environment gates (staging → production), meaning code must pass each environment before being promoted — you don't want to deploy straight from main as in GitHub Flow. (2) You need versioning/multi-version support but Git Flow is too complex. (3) A web app with a multi-step deployment pipeline that still wants a more flexible release cadence than traditional Git Flow.
-
What does atomic PR mean? Why does it matter?
Show answer
An atomic PR solves a single problem, can be reviewed in under 30 minutes, and can be deployed independently. It matters because: (1) the reviewer understands the context easily and reviews better, (2) if a revert is needed, you only revert one clear feature, (3) it avoids bottlenecks — small PRs merge faster and don't block colleagues.
-
What is the difference between
squashandfixupin interactive rebase?Show answer
Both combine a commit into the previous one. The difference:
squashopens the editor so you can edit the combined commit message (both messages merged together).fixupdiscards this commit's message and keeps only the previous commit's message — suitable when the commit is a minor fix that doesn't need its own explanation (e.g. a typo fix). -
What message does
git commit --fixup <hash>create?Show answer
It automatically creates a message in the format
fixup! <original-commit-message>. For example, if the original commit's message is"feat: add login form"→ the fixup commit's message will be"fixup! feat: add login form". Git uses thisfixup!prefix sogit rebase -i --autosquashcan automatically reorder and squash it into the right place. -
When do you use
rewordinstead ofsquashin interactive rebase?Show answer
Use
rewordwhen you want to only change the commit message without changing the content or combining it with another commit. For example: the commit message has a typo, you need to add a ticket ID, or you want to changeWIP: ...into a proper Conventional Commits message.squashcombines the content of several commits;rewordonly edits the message of a single commit. -
Why must you use
--force-with-leasewhen pushing aftergit rebase -i?
Show answer
Interactive rebase rewrites history — every edited commit gets a new hash. The remote branch still has the commits with the old hashes. Git rejects a normal push because the local history has "diverged" from the remote. You need a force push to overwrite the remote. Use --force-with-lease (not --force) to make sure you don't overwrite colleagues' commits if they pushed while you were rebasing.
- Why is a semantic conflict more dangerous than a textual conflict?
Show answer
Git detects textual conflicts and reports them directly — you know you need to resolve them. A semantic conflict is when the merge is clean (no conflict markers) but the logic is wrong: e.g. Dev A renames a function while Dev B still calls the old name. The merge succeeds, CI passes if test coverage is low, but production crashes. No tool detects it automatically — only careful code review, TypeScript/static analysis, and integration tests catch it.
- What does the
diff3conflict style add compared to the default?
Show answer
diff3 (enabled with git config --global merge.conflictstyle diff3) adds a third section among the markers: ||||||| base — showing the content before either branch changed it (the common ancestor). This helps you understand the context: you see what the original value was, how HEAD changed it, and how the feature branch changed it — making the resolution decision easier than seeing only 2 versions.
- What problem does
git rereresolve in long-running feature branches?
Show answer
Long-running feature branches have to be rebased onto main frequently. If the same conflict appears many times (e.g. a config file edited by both branches), you have to resolve it manually on every rebase. rerere (Reuse Recorded Resolution) remembers how you resolved it the first time and automatically reapplies it afterwards — saving time and avoiding inconsistent resolutions.
- What is the difference between a merge commit (
--no-ff) and a squash merge?
Show answer
Merge commit (--no-ff): keeps all the feature branch's commits in history and creates a merge commit with 2 parents — the history clearly shows the fork, with a full audit trail. Squash merge: combines all the feature's commits into a single commit on main — very clean main history (each entry = one feature), but you lose the detail of how the feature was developed. GitHub PR squash merge works this way.
- Which command lists all files with unresolved conflicts?
Show answer
git diff --name-only --diff-filter=U (U = Unmerged). Or git status | grep "both modified". While a merge is in progress, git status also clearly shows "Unmerged paths". After resolving each file you must git add <file> to mark it resolved before git commit or git rebase --continue.
Hands-on Exercises
Part 1: Workflow Models — Choosing the Right Strategy for Your Team
# Simulate Git Flow for a small feature
mkdir workflow-lab && cd workflow-lab
git init -b main
git config user.name "Test" && git config user.email "test@test.com"
# Setup: create main and develop
echo "v1.0.0" > version.txt
git add . && git commit -m "chore: initial commit"
git switch -c develop
echo "develop" > develop.txt
git add . && git commit -m "chore: setup develop branch"
# Feature branch
git switch -c feature/user-search
echo "search feature" > search.js
git add . && git commit -m "feat: add user search"
# Merge back into develop (--no-ff as in Git Flow)
git switch develop
git merge --no-ff feature/user-search -m "feat: merge user search feature"
git branch -d feature/user-search
# Release branch
git switch -c release/1.1.0
echo "1.1.0" > version.txt
git add . && git commit -m "chore: bump version to 1.1.0"
# Merge into main
git switch main
git merge --no-ff release/1.1.0 -m "release: version 1.1.0"
git tag -a v1.1.0 -m "Release 1.1.0"
# Merge back into develop
git switch develop
git merge --no-ff release/1.1.0
git branch -d release/1.1.0
# View the history
git log --oneline --graph --all
Part 2: Pull Requests, Code Review and Interactive Rebase
mkdir pr-rebase-lab && cd pr-rebase-lab
git init -b main
git config user.name "Test" && git config user.email "test@test.com"
# Setup
echo "app" > app.js && git add . && git commit -m "chore: init"
git switch -c feature/notifications
# Create a realistic "messy" commit history
echo "// notification" > notification.js
git add . && git commit -m "WIP: start notifications"
echo "const bell = () => {}" >> notification.js
git add . && git commit -m "feat: add bell component"
echo "// typo fix" >> notification.js
git add . && git commit -m "fix typo"
echo "const badge = () => {}" >> notification.js
git add . && git commit -m "feat: add badge"
echo "const dropdown = () => {}" >> notification.js
git add . && git commit -m "WIP: dropdown"
echo "export { bell, badge, dropdown }" >> notification.js
git add . && git commit -m "feat: complete notification module"
git log --oneline
# 6 commits, messy
# Interactive rebase: squash the WIP and fixups into 2 clean commits
git rebase -i HEAD~6
# Aim for:
# pick XXX feat: add notification bell and badge
# pick YYY feat: add notification dropdown and exports
git log --oneline
# → 2 tidy commits
# Practice --fixup
echo "// additional comment" >> notification.js
git add . && git commit --fixup HEAD~1 # fixup for the commit BEFORE the latest one (HEAD~1)
git log --oneline
# you see "fixup! feat: ..."
git rebase -i --autosquash HEAD~3
# See how autosquash arranges it
Part 3: Advanced Conflict Resolution
mkdir conflict-advanced-lab && cd conflict-advanced-lab
git init -b main
git config user.name "Test" && git config user.email "test@test.com"
# Enable rerere
git config rerere.enabled true
git config merge.conflictstyle diff3
# 1. Create a repeatable conflict (to test rerere)
echo "timeout: 30" > config.yml
git add . && git commit -m "chore: init config"
git switch -c feature/retry
echo "timeout: 60" > config.yml
git add . && git commit -m "feat: increase timeout"
git switch main
echo "timeout: 45" > config.yml
git add . && git commit -m "feat: medium timeout for main"
# 2. First time: resolve manually
git merge feature/retry
# → CONFLICT in config.yml with diff3 markers
# → "Recorded preimage for 'config.yml'" — rerere remembers the conflict
# Resolve: timeout: 60
echo "timeout: 60" > config.yml
git add config.yml && git commit
# → "Recorded resolution for 'config.yml'." — rerere remembers the resolution
# 3. Undo the merge commit to reproduce exactly the same conflict
# (rerere data lives in .git/rr-cache and is not lost on reset)
git reset --hard HEAD~1
# 4. Second merge — rerere applies it automatically
git merge feature/retry
# Git reports: "Resolved 'config.yml' using previous resolution."
# The merge still stops in a conflict state, but the file is already filled with the resolution
cat config.yml # → timeout: 60 (no conflict markers left)
git add config.yml && git commit
# 5. Test --no-ff
git switch -c feature/no-ff-test
echo "new feature" >> config.yml
git add . && git commit -m "feat: no-ff test"
git switch main
git merge --no-ff feature/no-ff-test -m "feat: merge no-ff-test"
git log --oneline --graph
# You see a merge commit with 2 parents
References
- A successful Git branching model (Vincent Driessen)
- GitHub Flow
- GitLab Flow
- Trunk-Based Development
- git rebase documentation
- GitHub: Reviewing proposed changes in a PR
- Atlassian: git rebase -i
- git rerere documentation
- git mergetool documentation
- Advanced Merging
- Atlassian: Resolve merge conflicts