This guide shows a clean setup for editing MkDoxy across multiple branches at once using git worktree
.
- Git 2.38+ recommended
- A root dev folder (examples use
~/code
)
mkdir -p ~/code && cd ~/code
git clone [email protected]:JakubAndrysek/MkDoxy.git
cd MkDoxy
# Nice defaults
git config worktree.guessRemote true
git config fetch.prune true
git config remote.origin.prune true
Keep this primary copy on main
and up to date.
Create a sibling folder for all extra worktrees (not inside the repo):
mkdir -p ~/code/wt/mkdoxy
Example layout:
~/code/
MkDoxy/
wt/
mkdoxy/
feat/new-parser/
fix/issue-123/
pr/456/
rel/v0.8.0/
cd ~/code/MkDoxy
git fetch origin
git worktree add ~/code/wt/mkdoxy/feat/new-parser -b feat/new-parser origin/main
git fetch origin
git worktree add ~/code/wt/mkdoxy/fix/issue-123 origin/fix/issue-123
git fetch origin pull/456/head:pr/456
git worktree add ~/code/wt/mkdoxy/pr/456 pr/456
git fetch --tags
git worktree add ~/code/wt/mkdoxy/rel/v0.8.0 v0.8.0
-
Update primary:
cd ~/code/MkDoxy git pull --rebase --autostash
-
Work inside a worktree:
cd ~/code/wt/mkdoxy/feat/new-parser git add -A git commit -m "feat(parser): initial block handling" git push -u origin feat/new-parser
-
Open a PR on GitHub from that branch.
-
List all worktrees:
git worktree list
-
Remove a finished worktree (clean dir):
git worktree remove ~/code/wt/mkdoxy/feat/new-parser
-
Prune stale metadata:
git worktree prune
- A branch can be checked out in only one worktree at a time.
- Don’t put worktrees inside another Git repo.
- Hooks are shared (live in the main repo’s
.git/hooks
). - For submodules, run
git submodule update --init --recursive
inside each worktree when needed.
Add to ~/.gitconfig
:
[alias]
wt = worktree
wtls = worktree list
wtadd = !f() { git worktree add "$@"; }; f
wtrm = !f() { git worktree remove "$@"; }; f
Usage:
git wtls
git wtadd ~/code/wt/mkdoxy/feat/new-parser -b feat/new-parser origin/main
git wtrm ~/code/wt/mkdoxy/feat/new-parser
Happy hacking! With this layout, you can freely build, test, and compare branches of MkDoxy side-by-side without juggling stashes or re-checkouts.