Review a Pull Request in a Separate Worktree
Check out a PR branch for code review without leaving your current feature work.
When to use
A teammate asks for a code review, but you are in the middle of uncommitted changes on your feature branch. Use a worktree to check out their PR branch separately.
Pre-flight
- Know the PR number or branch name you need to review.
- Ensure you have fetch access to the remote repository.
Steps
-
Fetch the PR branch from GitHub. This creates a local reference you can check out.
git fetch origin pull/123/head:pr-123Replace
123with the actual PR number. -
Create a worktree for the PR branch in a sibling directory.
git worktree add ../review-pr-123 pr-123 -
Navigate to the review directory and explore the code.
cd ../review-pr-123 # Run tests, check linting, review changes npm test npm run lint -
Once the review is complete, return to your main directory and clean up.
cd ../your-main-repo git worktree remove ../review-pr-123 git branch -d pr-123
Verification
git worktree listshows only your main worktree after cleanup.- Your original feature branch remains untouched with all uncommitted changes intact.
Alternative: Review a remote branch directly
If the PR branch is already pushed to origin, skip the fetch step:
git worktree add ../review-feature origin/feat/user-auth
Follow-up
- Leave your review comments on the PR in GitHub.
- If changes are needed, the author can push updates and you can pull them into the same worktree.