Skip to main content

Command Palette

Search for a command to run...

🚀 Introduction to Git Worktree

and Boost Git Worktree Efficiency with Oh My Zsh Aliases

Published
4 min read
🚀 Introduction to Git Worktree
P

CS post-grad | I talk about Deep Learning, AI, OS, Computer Architecture & Web.

If you’ve ever had to switch branches in the middle of work, stash your changes, or juggle multiple clones of the same repository… you already know the pain.

Good news: Git Worktree makes all of this much easier.

This guide will introduce:

  • What Git Worktree is
  • What Oh My Zsh is (and why its aliases help)
  • Real workflows for single-repo apps
  • Real workflows for monorepos

Let’s make your Git life smoother and your workflow faster. ✨


🌱 What is Git Worktree?

A Git worktree is a feature that lets you check out multiple branches of the same repo at the same time — each in its own folder.

Think of it like having multiple “workspaces” linked to the same Git repository.

Why use it?

  • No need to clone the repo again
  • No need to stash or reset your local changes
  • You can develop, test, or review PRs in parallel
  • Saves time and disk space
  • Cleaner workflow

Example: You’re working on feature/homepage-redesign but your teammate asks you to check hotfix/login-bug.

Instead of stashing everything:

git worktree add ../login-hotfix origin/hotfix/login-bug

Boom — a new folder opens up with that branch, while your original branch stays untouched.


🌀 What is Oh My Zsh? And Why Are We Talking About It?

If you use Zsh (default shell on macOS), then Oh My Zsh is like a power-up.

It’s a framework that adds:

  • Useful plugins
  • Completion
  • Themes
  • Shortcuts
  • And… Git aliases that save a LOT of typing

Instead of typing:

git worktree add ../some-folder feature-branch

With the Oh My Zsh git plugin, you can type:

gwta ../some-folder feature-branch

Here are the key aliases for Git Worktree:

AliasFull commandMeaning
gwtgit worktreeBase command
gwtagit worktree addAdd a worktree
gwtlgit worktree listList worktrees
gwtrgit worktree removeRemove worktree
gwtpgit worktree pruneRemove stale entries

To enable it, make sure your .zshrc has:

plugins=(git)

Reload:

source ~/.zshrc

And you’re set.


⚙️ Workflow Scenario 1 — Single-Repo App

Let’s say you have a normal project:

my-app/
  src/
  package.json
  ...

You’re working on a big feature:

feature/new-ui

But someone needs your help reviewing:

feature/navbar-fix

Instead of stopping your work:

➕ Add a worktree

gwta ../navbar-fix-wt origin/feature/navbar-fix

Now you have:

my-app/                  ← your main work continues here
navbar-fix-wt/           ← completely separate workspace

👇 Inside navbar-fix-wt/

  • Open code
  • Run tests
  • Try builds
  • Review changes

When done:

gwtr ../navbar-fix-wt

Back to your original branch, untouched.

🔥 Why this is awesome

  • No stashing
  • No losing uncommitted changes
  • No slow clones
  • You can have 3–4 worktrees open if you want

🏗️ Workflow Scenario 2 — A Monorepo with Multiple Apps

A common setup:

company-monorepo/
  apps/
    web/
    admin/
    mobile/
  libs/
    ui/
    utils/

Now imagine you need to:

  • Work on web-app-feature
  • Test something in admin
  • Also prepare a PR fix for mobile

Instead of checking out branches back and forth:

1️⃣ Create worktrees for each branch

gwta ../wt-web-feature web-app-feature
gwta ../wt-admin-experiments admin-dashboard-refactor
gwta ../wt-mobile-fix mobile/login-crash

Folder layout becomes:

company-monorepo/           ← your main repo
wt-web-feature/
wt-admin-experiments/
wt-mobile-fix/

Each folder is:

  • A checkout of a different branch
  • Still shares the same .git data
  • Fast to create (no re-cloning!)

2️⃣ Work in each independently

cd ../wt-web-feature
npm run dev:web

cd ../wt-admin-experiments
npm run dev:admin

cd ../wt-mobile-fix
npm run dev:mobile

Yes, you can run multiple apps side-by-side — perfect for monorepos.

3️⃣ Clean up when you’re done

gwtr ../wt-web-feature
gwtr ../wt-admin-experiments
gwtr ../wt-mobile-fix

🎯 Final Thoughts

Git Worktree is one of those features that feels small but saves huge amounts of time once you start using it.

Combined with Oh My Zsh’s aliases:

  • Faster workflows
  • Cleaner development environments
  • No more “stash → switch → test → switch back” loop
  • Perfect for multitasking across branches
  • Perfect for monorepos where multiple apps run at once

If you work on anything slightly complex - frontend frameworks, backend services, monorepos (& ServiceNow apps in my case) - Git Worktree is a superpower 💪