Skip to content

Instantly share code, notes, and snippets.

@benprew
Last active December 5, 2019 00:40
Show Gist options
  • Save benprew/d168db607601f97fd2df0a00a4f386d7 to your computer and use it in GitHub Desktop.
Save benprew/d168db607601f97fd2df0a00a4f386d7 to your computer and use it in GitHub Desktop.

How I setup my worktrees:

$ ll ~/work/analytical-solutions-trees drwxrwsr-x 81 bprew rtk 8.0K Nov 15 17:36 faster-rap-tags drwxrwxr-x 82 bprew rtk 8.0K Sep 11 22:27 master drwxrwsr-x 81 bprew rtk 8.0K Nov 13 16:20 migrate-as-linear-to-vpc

Adding a new worktree:

I have a git script named "start" that I use when I want to add a new worktree

ex. (in master/) git start geomap

That creates a new worktree and cd's into it.

#!/bin/bash

BRANCH_NAME=personal/$USER/$1
WORK_DIR=../$1

# cleanup old remote branches
git remote prune origin

git checkout master
git pull --ff-only
git worktree add -b $BRACH_NAME $WORK_DIR

# move to newly created work directory
cd $WORK_DIR

# push and set upstream
git push -u origin $BRANCH_NAME

Cleaning up a worktree

# make sure there's not outstanding changes in the tree
git status
# remove the directory
rm -rf ../<worktree>/
# cleanup worktree list
cd master && git worktree prune
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment