Skip to content

Instantly share code, notes, and snippets.

@filipenf
Created July 12, 2018 14:15
Show Gist options
  • Save filipenf/8026c890a7f31902b4d61d74f0de982a to your computer and use it in GitHub Desktop.
Save filipenf/8026c890a7f31902b4d61d74f0de982a to your computer and use it in GitHub Desktop.
git worktree
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