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
gwtfunction 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
-bcreates the branch if it does not exist--cdautomatically moves to the worktree after creation. Not necessary if you setautoCdingwt init--no-cdthe opposite of--cd. Useful for disablingautoCdfrominitfor individual commands--path|-pprovide an explicit location for the worktree to be created, overriding the default--dry-runprefixes all destructive commands withechoso 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-runprefixes all destructive commands withechoso 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|-foverride unpushed and dirty state checks and force deletion--dry-runprefixes all destructive commands withechoso you can inspect the output before commiting--delete-branch|-dbdeletes the branch withgit branch -dafter removing the worktree. If-fis provided, usesgit branch -Dinstead. Can be made automatic withgwt init--preserve-branch|-pbensures the branch is not deleted, even if the--delete-branchbehavior 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|-malso prints the primary worktree in the output, and adds a new columnTYPEwith a value ofmainorlinkedto designate the type of worktree--porcelainremoves 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|-foverride unpushed and dirty state checks and force deletion of all worktrees--dry-runprefixes all destructive commands withechoso you can inspect the output before commiting
Initializes persistent user settings in ~/.config/gwt/settings.json.
Allows setting of:
autoCd- makes the--cdflag ongwt addautomaticworktreeLocation- overrides the default~/worktreesstarting path for storing worktreesdeleteBranchWithTree- sets upgwt rmto automatically rungit branch -d(orgit branch -Dif the-fflag 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.gitsymlink that points to the main worktree's.git/worktrees/<branch> - linked worktree: a "satellite" worktree, with the symlinked
.git