-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathworktree-add
More file actions
executable file
·28 lines (23 loc) · 1023 Bytes
/
Copy pathworktree-add
File metadata and controls
executable file
·28 lines (23 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash
#
# Create a git worktree in the .worktrees directory of the current repository.
set -x
if [ -z "$1" ]; then
echo "Usage: $(basename "$0") <branch_name>"
echo ""
echo "Create a git worktree in the .worktrees directory of the current repository."
exit 1
fi
branch_name="$1"
repository_root=`git rev-parse --show-toplevel`
branch_directory=`echo $branch_name | sed 's/[^a-zA-Z0-9]/-/g'`
worktree_directory=$repository_root/.worktrees/$branch_directory
mkdir -p "$repository_root/.worktrees"
git worktree add $worktree_directory $branch_name || git worktree add $worktree_directory -b $branch_name
# Copy local config files to the new worktree
[ -f "$repository_root/.env" ] && cp "$repository_root/.env" "$worktree_directory/.env"
if [ -f "$repository_root/.claude/settings.local.json" ]; then
mkdir -p "$worktree_directory/.claude"
cp "$repository_root/.claude/settings.local.json" "$worktree_directory/.claude/settings.local.json"
fi
echo "Worktree added under $worktree_directory"