Skip to content

Instantly share code, notes, and snippets.

@SpainTrain
Created September 22, 2016 17:50
Show Gist options
  • Save SpainTrain/e555a17a34ed39267b1b17dadeed5b72 to your computer and use it in GitHub Desktop.
Save SpainTrain/e555a17a34ed39267b1b17dadeed5b72 to your computer and use it in GitHub Desktop.
Checkout a new branch in a git worktree
#!/bin/bash
GIT_REPO_NAME=$(basename `git rev-parse --show-toplevel`)
BRANCH_NAME=${1}
WORKTREES_DIR="${HOME}/worktrees"
mkdir -p ${WORKTREES_DIR}/${GIT_REPO_NAME}
git branch ${BRANCH_NAME}
git worktree add ${WORKTREES_DIR}/${GIT_REPO_NAME}/${BRANCH_NAME} ${BRANCH_NAME}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment