DEV Community

Cover image for Review Pull Requests with git worktrees
Waylon Walker
Waylon Walker

Posted on • Originally published at waylonwalker.com

Review Pull Requests with git worktrees

Sometimes you get a PR on a project, but cannot review it without wrecking your current working setup. This might be because it needs to be compiled, or a new set of requirements. Git worktrees is a great way to chekout the remote branch in a completely separate directory to avoid changing any files in your current project.

# pattern
# git worktree add -b <branch-name> <PATH> <remote>/<branch-name>
git worktree add -b fix-aws-service-cnsn /tmp/project origin/fix-aws-service-cnsn
Enter fullscreen mode Exit fullscreen mode

This will create a new directory /tmp/project that you can review the branch
fix-aws-service-cnsn from the remote origin. If you have setup different remotes locally you can check for the name of it with git remote -v

Top comments (0)