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.
- Host: GitHub
- URL: https://github.com/kfly8/git-wo
- Owner: kfly8
- Created: 2025-12-01T01:17:01.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-12-29T03:30:14.000Z (6 months ago)
- Last Synced: 2025-12-31T22:16:39.108Z (6 months ago)
- Topics: git
- Language: Shell
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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