# arguments
worktree-make <branch_create> [<branch_from>]
An easier way to make git worktrees and branches for projects that have multiple repositories.
Review the install.sh and worktree-make.sh files before installing.
For easy installation. Run the following curl statement to add the worktree-make
function to your shell configuration file. Append the statement with the name of the target configuration file.
For example, if using Bash on Linux:
curl https://raw.githubusercontent.com/joematthews/worktree-make/main/install.sh | bash -s -- ~/.bashrc
Or, if using Zsh on macOS:
curl https://raw.githubusercontent.com/joematthews/worktree-make/main/install.sh | bash -s -- ~/.zshrc
Then run source
on the configuration file (~/.zshrc in this example):
source ~/.zshrc
Clone the repository and run the install.sh script. Append the statement with your shell configuration file (~/.zshrc in this example):
git clone git@github.com:joematthews/worktree-make.git
./install.sh ~/.zshrc
source ~/.zshrc
To quickly create a worktree within a git repository, enter a branch name:
cd project-repository
worktree-make feat/555-products-backorder
This will create a new directory at ../worktrees/feat/555-products-backorder/project-repository
and then change to that directory automatically with pushd
. The feat/555-products-backorder
branch will already by checked out.
To return to the original repository use popd
.
By default, worktree-make branches off of main
. To branch off of a different branch, append the branch name to the end:
worktree-make feat/555-products-backorder master
The generated directory structure is helpful because some projects have multiple repositories (ex: backend and frontend).
If the same exact branch name is chosen (ex: chore/666-refactor-users
), then multiple repositories will reside within the directory for that branch. For example:
# terminal 1
cd project-frontend
worktree-make chore/666-refactor-users
# terminal 2
cd project-backend
worktree-make chore/666-refactor-users
...will generate the following directories:
../worktrees/chore/666-refactor-users/project-frontend
../worktrees/chore/666-refactor-users/project-backend
To clean up the worktrees simply delete the parent branch directory:
rm -r worktrees/chore/666-refactor-users
And then for each related repository, prune the worktrees:
# within project-frontend & project-backend
git worktree prune
And then finally, delete the branch in each repository:
# within project-frontend & project-backend
git branch -d chore/666-refactor-users