Skip to content

Instantly share code, notes, and snippets.

@SpainTrain
Last active March 13, 2019 19:03
Show Gist options
  • Save SpainTrain/36ef7ccc1668f683fafb3278f1a3b6bd to your computer and use it in GitHub Desktop.
Save SpainTrain/36ef7ccc1668f683fafb3278f1a3b6bd to your computer and use it in GitHub Desktop.
git checkout PR into git worktree
#!/bin/bash
GIT_REPO_NAME=$(basename `git rev-parse --show-toplevel`)
PR_NUM=${1}
WORKTREES_DIR="${HOME}/worktrees"
mkdir -p ${WORKTREES_DIR}/${GIT_REPO_NAME}
# requires `git fetch-pr` alias credit: https://gist.github.com/gnarf/5406589
# fetch-pr = "!f() { git fetch -fu ${2:-$(git remote |grep ^upstream || echo origin)} refs/pull/$1/head:pr/$1; }; f"
git fetch-pr ${PR_NUM}
git worktree add ${WORKTREES_DIR}/${GIT_REPO_NAME}/pr-${PR_NUM} pr/${PR_NUM}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment