Created
July 13, 2025 12:58
-
-
Save andreagrandi/542b438bf0017d93aff2b640037e3ce1 to your computer and use it in GitHub Desktop.
Script to create a git worktree and link existing virtualenv and .envrc files
This file contains hidden or 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 | |
set -e | |
# Usage: ./git-add-worktree.sh <base-branch> <new-branch-name> | |
BASE_BRANCH="$1" | |
NEW_BRANCH="$2" | |
WORKTREE_PATH="../my-project-worktrees/$NEW_BRANCH" | |
# Create the worktree and new branch from base | |
git worktree add -b "$NEW_BRANCH" "$WORKTREE_PATH" "$BASE_BRANCH" | |
# Set up symlinks from the new worktree folder | |
cd "$WORKTREE_PATH" | |
ln -s ../../my-project/.venv .venv | |
ln -s ../../my-project/.envrc .envrc | |
direnv allow | |
echo "✅ Worktree for '$NEW_BRANCH' based on '$BASE_BRANCH' set up at '$WORKTREE_PATH'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment