Last active
March 13, 2019 19:03
-
-
Save SpainTrain/36ef7ccc1668f683fafb3278f1a3b6bd to your computer and use it in GitHub Desktop.
git checkout PR into git worktree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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