An open API service indexing awesome lists of open source software.

https://github.com/kfly8/git-wo

A thin wrapper around git worktree that creates worktrees in a ghq-style directory structure.
https://github.com/kfly8/git-wo

git

Last synced: 6 months ago
JSON representation

A thin wrapper around git worktree that creates worktrees in a ghq-style directory structure.

Awesome Lists containing this project

README

          

# git-wo

A thin wrapper around `git worktree` that creates worktrees in a ghq-style directory structure.

## Overview

`git-wo` organizes worktrees under `~/worktree////`, making it easy to manage multiple worktrees across different repositories.

```
~/worktree/github.com/kfly8/my-project/feature1
~/worktree/github.com/kfly8/my-project/feature2
~/worktree/gitlab.com/team/other-repo/bugfix
```

## Installation

```bash
curl -o ~/bin/git-wo https://raw.githubusercontent.com/kfly8/git-wo/main/git-wo
chmod +x ~/bin/git-wo
```

Make sure `~/bin` is in your `PATH`.

## Usage

```bash
# Create a new worktree (creates new branch from current HEAD)
git wo add feature1

# Create a new worktree from a specific branch
git wo add feature1 main

# Pass options to git worktree add
git wo add feature1 main --track

# List worktrees
git wo list

# Remove a worktree
git wo remove feature1

# Remove all worktrees for merged branches
git wo prune-merged

# Prune stale worktree info
git wo prune
```

## Configuration

Configure via `git config`:

```bash
# Set worktree root directory (default: ~/worktree)
git config --global wo.root ~/worktree

# Set post-create hook script
git config --global wo.postHook ~/.config/git-wo/post-hook
```

### Post Hook

The `wo.postHook` script runs after creating a worktree. Environment variables available:

- `ORIGINAL_PATH`: Path to the original repository
- `WORKTREE_PATH`: Path to the new worktree
- `BRANCH_NAME`: Name of the new branch

Example hook script (`~/.config/git-wo/post-hook`):

```bash
#!/bin/bash
cp "$ORIGINAL_PATH/.envrc" "$WORKTREE_PATH/" 2>/dev/null
direnv allow "$WORKTREE_PATH"
mise trust "$WORKTREE_PATH"
```

Don't forget to make it executable: `chmod +x ~/.config/git-wo/post-hook`

## Tips

### fzf integration

Add to your `.zshrc` to jump between worktrees with `Ctrl-G`:

```bash
function fzf-worktree () {
local selected=$(git worktree list 2>/dev/null | fzf --query="$LBUFFER" | awk '{print $1}')
if [ -n "$selected" ]; then
BUFFER="cd ${selected}"
zle accept-line
fi
zle reset-prompt
}
zle -N fzf-worktree
bindkey '^g' fzf-worktree
```

## License

MIT