An opinionated git worktree
manager. Makes the most frequent commands easier.
Automatically organizes worktrees in a sane default location: ~/worktrees/<repo>/<branch>
.
# Can only be run in a git repository
% cd ~/src/my-project
# Create a new branch and worktree, and move to it
% gwt add -b my-branch --cd
% pwd #=> $HOME/worktrees/my-project/my-branch
# Do work, forget where you're at and what other work you have ongoing
% gwt status -m
TYPE BRANCH PATH STATE
main main $HOME/src/my-project clean
linked my-branch $HOME/worktrees/my-project/my-branch dirty + unpushed
# Finish your work, merge it, time to clean up, go back to the main repo
% gwt rm .
- Simple - copy the
gwt
function somewhere that your zsh config will autosource it into your shell - Nix home-manager flake - use the flake as an input to nix home-manager, as below:
# home-manager flake.nix
{
inputs = {
# Other inputs...
gwt = {
url = "github:flyinggrizzly/gwt";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { ... }: {
homeConfigurations.username = home-manager.lib.homeManagerConfiguration {
modules = [
inputs.gwt.homeManagerModules.default
];
};
};
}
Aliases: gwt add
, gwt a
-b
creates the branch if it does not exist--cd
automatically moves to the worktree after creation. Not necessary if you setautoCd
ingwt init
--no-cd
the opposite of--cd
. Useful for disablingautoCd
frominit
for individual commands--path|-p
provide an explicit location for the worktree to be created, overriding the default--dry-run
prefixes all destructive commands withecho
so you can inspect the output before commiting
Aliases: gwt cd
, gwt co
When called with <branch>
, moves to that linked worktree. When called without an argument, moves to the primary/parent
worktree.
Includes the co
alias since gwt co
and gwt cd
are notionally the same operation for existing worktrees.
--dry-run
prefixes all destructive commands withecho
so you can inspect the output before commiting
Aliases: gwt remove
, gwt rm
Removes the worktree for the specified branch, or path. Has special handling for gwt rm .
which will first gwt cd
to
the main worktree, and then remove the worktree.
--force|-f
override unpushed and dirty state checks and force deletion--dry-run
prefixes all destructive commands withecho
so you can inspect the output before commiting--delete-branch|-db
deletes the branch withgit branch -d
after removing the worktree. If-f
is provided, usesgit branch -D
instead. Can be made automatic withgwt init
--preserve-branch|-pb
ensures the branch is not deleted, even if the--delete-branch
behavior is enabled with a flag orgwt init
Aliases: gwt status
, gwt st
, gwt s
Prints all linked worktrees showing BRANCH
, PATH
, and STATE
.
STATE
will show "clean"
if the branch/tree is clean and up to date with any remotes, and "dirty"
/"unpushed"
if
the branch/worktree is dirty or has unpushed changes (only relevant if there is a remote).
--with-main|-m
also prints the primary worktree in the output, and adds a new columnTYPE
with a value ofmain
orlinked
to designate the type of worktree--porcelain
removes the column headers to improve machine readability
Removes all linked worktrees (excluding the main worktree). Useful for cleaning up after feature work is complete.
--force|-f
override unpushed and dirty state checks and force deletion of all worktrees--dry-run
prefixes all destructive commands withecho
so you can inspect the output before commiting
Initializes persistent user settings in ~/.config/gwt/settings.json
.
Allows setting of:
autoCd
- makes the--cd
flag ongwt add
automaticworktreeLocation
- overrides the default~/worktrees
starting path for storing worktreesdeleteBranchWithTree
- sets upgwt rm
to automatically rungit branch -d
(orgit branch -D
if the-f
flag is set)
Requires jq
.
- primary/parent worktree: the "main" location of the repo. This is identified by the worktree that includes a
.git/
directory, instead of a.git
symlink that points to the main worktree's.git/worktrees/<branch>
- linked worktree: a "satellite" worktree, with the symlinked
.git