Created
August 28, 2025 14:47
-
-
Save clayallsopp/f372530d2e4459fd9d031d56106306b0 to your computer and use it in GitHub Desktop.
Shell functions for worktrees
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
| # S/o @amazure | |
| # https://plaidchat.slack.com/archives/C08DR1W3P4Y/p1750771726729969?thread_ts=1750699090.902789&cid=C08DR1W3P4Y | |
| gwtb() { | |
| if [ $# -ne 1 ]; then | |
| echo "Usage: gwtb <worktree_dir>" | |
| return 1 | |
| fi | |
| local WORKTREE_NAME="$1" | |
| local BRANCH_NAME="$USER-$WORKTREE_NAME" | |
| local WORKTREE_PATH="$PLAID_PATH/$WORKTREE_NAME" | |
| git worktree add -b "$BRANCH_NAME" "$WORKTREE_PATH" HEAD || return 1 | |
| echo "Created new branch '$BRANCH_NAME' with worktree at '$WORKTREE_PATH'" | |
| # Create symlink to ./bin in the new worktree | |
| if [ -d "./bin" ]; then | |
| ln -s "$(realpath ./bin)" "$WORKTREE_PATH/bin" | |
| fi | |
| cd "$WORKTREE_PATH" | |
| } | |
| gwt() { | |
| if [ $# -ne 1 ]; then | |
| echo "Usage: gwt <worktree_dir>" | |
| return 1 | |
| fi | |
| local WORKTREE_NAME="$1" | |
| local BRANCH_NAME="$USER-$WORKTREE_NAME" | |
| local WORKTREE_PATH="$PLAID_PATH/$WORKTREE_NAME" | |
| git worktree add "$WORKTREE_PATH" "$BRANCH_NAME" || return 1 | |
| echo "Attached worktree at '$WORKTREE_PATH' to branch '$BRANCH_NAME'" | |
| # Create symlink to ./bin in the new worktree | |
| if [ -d "./bin" ]; then | |
| ln -s "$(realpath ./bin)" "$WORKTREE_PATH/bin" | |
| fi | |
| cd "$WORKTREE_PATH" | |
| } | |
| cdwt() { | |
| cd "$PLAID_PATH/$1" || echo "Directory '$PLAID_PATH/$1' does not exist" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment