Created
July 12, 2018 14:15
-
-
Save filipenf/8026c890a7f31902b4d61d74f0de982a to your computer and use it in GitHub Desktop.
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
function worktree_add() { | |
## Run this function in the top level directory of a git repo | |
## to create a worktree directory from a new or existing branch | |
if [ -d ./.git ]; then | |
git rev-parse --verify "$1" | |
if [ $? -eq 0 ]; then | |
echo "Creating a worktree ../$1 from existing branch $1" | |
git worktree add "../$1" "$1" | |
else | |
echo "Creating a worktree ../$1 from a new branch $1" | |
git worktree add -b "$1" "../$1" master | |
fi | |
else | |
echo "You are not in the root of a git repo" | |
fi; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment