github CLI extension for worktrees
Project description
gh-worktree
A CLI tool that helps you manage Git worktrees. This was built as a GitHub CLI (gh) extension, but it can be used directly. Although it does rely on the following being available:
git(obviously)gh
When you use gh-worktree to initialize a repository for use with worktrees, it uses a bare repository approach, which creates a structure like the following, if you were to clone gh-worktree:
gh-worktree/
.bare/
.git # points git to .bare/
.gh/
worktree/
hooks/
config.json
When you create new worktrees, they'll be added as directories to the root directory:
gh-worktree/
# ... see above ...
my-new-worktree/
README.md
# ... etc ...
You may add hooks to .gh/worktree/hooks so that you may trigger custom functionality during the lifecycle of your worktrees. The hooks are configurable in the project, but also globally. The first global .gh/worktree/hooks found upwards in the directory tree, outside the project directory (i.e. above gh-worktree/), will be executed. The following hooks are available:
pre_init: before initializing a repository for use with worktrees (global only)post_init: after initializing a repository for use with worktrees (global only)pre_checkout: before a PR or other existing branch is checked out as a worktreepost_checkout: after a PR or other existing branch is checked out as a worktreepre_create: before a new worktree (branch) is createdpost_create: after a new worktree (branch) is createdpre_remove: before a worktree is removedpost_remove: after a worktree is removed
For example, you might consider adding a post_create hook for this project like:
#!/usr/bin/env bash
WORKTREE_NAME="$1"
BASE_REF="$2" # format: `remote/branch`
pushd "$WORKTREE_NAME"
uv venv
uv sync --group dev
popd
Commands
You may use --help for any command for usage information. To see a list of commands, run gh-worktree without any arguments.
Init
Spec: init <repository_uri> [optional_clone_dir]
Initializes the repository (e.g. https://github.com/bjester/gh-worktree.git) for use with this plugin and git worktrees. It's similar to git clone in that you can specify a name for the project directory as the second argument, otherwise it uses the repository name.
Create
Spec: create <worktree_name> [base_ref]
Creates a new worktree, which by default will be based off the default branch of the Github repository that you initialized the project with using init.
Checkout
Spec: checkout [--remote=<name>] <branch_name|pr_number|pr_url>
Similar to how gh lets you quickly checkout PRs, this command allows you to quickly create a worktree for a PR. This works even if the PR was opened from a fork of the project, and regardless of whether you've configured the fork as a remote.
Remove
Spec: remove [--force] <worktree_name>
Removes a worktree. If git detects the worktree has commits that are unmerged, then it will refuse to delete it. You may use --force to passthrough --force to git and force the worktree's deletion.
Installation as gh extension
TBD
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gh_worktree-0.1.0-py3-none-any.whl.
File metadata
- Download URL: gh_worktree-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
caa391586973d25b8e2ea6ec369cac25eb4b4bd33ae1d4d1f94f62683a84add9
|
|
| MD5 |
51c84299cef13b727a941edda07d365c
|
|
| BLAKE2b-256 |
e984c23ca7f2dfbf6e72c577451af5f879f48cbefce45098631878e971b51121
|
Provenance
The following attestation bundles were made for gh_worktree-0.1.0-py3-none-any.whl:
Publisher:
release.yml on bjester/gh-worktree
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gh_worktree-0.1.0-py3-none-any.whl -
Subject digest:
caa391586973d25b8e2ea6ec369cac25eb4b4bd33ae1d4d1f94f62683a84add9 - Sigstore transparency entry: 949439985
- Sigstore integration time:
-
Permalink:
bjester/gh-worktree@3bf33af2ef7b2c1f17f944ca564918041bdbfe20 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/bjester
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@3bf33af2ef7b2c1f17f944ca564918041bdbfe20 -
Trigger Event:
release
-
Statement type: