Git worktrees - Lesson 3 of 5

Integrate the change, not the directory

The worktree is a workspace. The branch and its commits are what you integrate. Decide whether the target needs the whole task branch or one selected commit, then verify in the target worktree.

Time: 12 minutesPrevious: createReference: field guide

First preserve the task

Inside the task worktree, make the change reviewable before touching the target branch:

cd ../repo-readme-refresh
git status --short
git add README.md
git commit -m "Refresh README setup instructions"
git log --oneline main..HEAD

The final command asks, in effect, which commits this task has that main does not. Read that range before choosing an integration method.

Choose deliberately

NeedUseTarget worktree action
The complete task branchMergegit merge docs/readme-refresh
Only one known commitCherry-pickgit cherry-pick <commit>
Linear history requiredFast-forward-only mergegit merge --ff-only docs/readme-refresh
Task needs its base updated before reviewRebase under team policyRebase in the task worktree, then re-test.
Do not rebase by reflex: rebase rewrites commits. Use it only when the repository's policy and collaborators make that safe.

Integrate in the target

cd ../repo
git switch main
git status --short
git pull --ff-only
git merge docs/readme-refresh
# Run the repository's relevant checks here.
git log --oneline --decorate -5

The target must be clean before you integrate. Resolve any conflict there, verify the resulting tree there, and only then mark the task complete.

Retrieval check

Primary reading

Ask follow-up questions: Show the agent your target branch, task branch, and commit range if you are unsure whether merge or cherry-pick is the smaller, safer move.