GitHub Blog

什么是 git worktrees,为什么我应该使用它们?

Git worktrees 允许开发者同时处理多个分支,无需暂存或切换上下文。它们创建独立的工作目录,实现并行开发并减少认知负担。由 GitHub Copilot 等 AI 工具推广,但需注意依赖和文件夹管理。

状态已摘要
抓取快照1
AI 输出2
开放问题0

已验证摘要

英文摘要

What are git worktrees, and why should I use them?

Git worktrees allow developers to work on multiple branches simultaneously without stashing or context switching. They create separate working directories, enabling parallel development and reducing mental overhead. Popularized by AI tools like GitHub Copilot, worktrees manage dependencies and folder bloat but require careful management.

  • Worktrees eliminate the need for stashing and context switching.
  • Each worktree is a separate folder with its own dependencies.
  • They enable parallel work and are ideal for AI-driven development.
  • Worktrees have been available since 2015 but are gaining popularity now.
  • Potential downsides include dependency bloat and folder management.
  • GitHub Copilot app uses worktrees by default.
  • You cannot check out the same branch in two worktrees simultaneously.

中文摘要

什么是 git worktrees,为什么我应该使用它们?

Git worktrees 允许开发者同时处理多个分支,无需暂存或切换上下文。它们创建独立的工作目录,实现并行开发并减少认知负担。由 GitHub Copilot 等 AI 工具推广,但需注意依赖和文件夹管理。

  • Worktrees 消除了暂存和上下文切换的需要。
  • 每个 worktree 是一个独立的文件夹,拥有自己的依赖。
  • 它们支持并行工作,非常适合 AI 驱动的开发。
  • Worktrees 自2015年就已存在,但现在才开始流行。
  • 潜在的缺点包括依赖膨胀和文件夹管理。
  • GitHub Copilot 应用默认使用 worktrees。
  • 你不能同时在两个 worktrees 中检出同一个分支。

git / git worktrees / GitHub Copilot / GitHub Copilot app / parallel development / context switching

完整文章

Cassidy Williams · @cassidoo

June 16, 2026|

5 minutes

Share:It seems like the latest hotness in git these days is the concept of worktrees. Which… is kind of funny because they’ve been around since 2015.But, nevertheless, they are cool, and you might be wondering why you’d use them, how they differ from branches, and why they are suddenly so popular.Let’s talk about it!Context switching with branches and stashingLet’s say you lived in a worktree-less world, and were working on a ticket, and suddenly an urgent bug came to you and you had to switch contexts.First, you might stash your work:git stash "wip feature login"Then you’d switch to your main branch and update:git checkout main

git pull origin mainThen make a bugfix branch:git checkout -b hotfix-bugThen you’d fix everything, commit, and push the branch:git add .

git commit -m "fix broken submit button"

git push origin hotfix-bugThen after merging a pull request, you might return back to your computer and pull main and remove the bug branch:git checkout main

git pull origin main

git branch -d hotfix-bugAnd then you could go back to the feature you were working on:git checkout feature-login

git stash popPhew. Where were we?The mental overhead of switching around, reloading files, reinstalling node_modules based on whatever changed, and so on, is a lot. The context switching burden is heavy.Now, this is a basic example, but sometimes developers would work around this kind of chaos with doing some more complicated git stash commands, or even multiple clones of the same repo (I’m guilty of that one).Until… worktrees!Context switching with worktreesWith worktrees, you never leave your branch and you never stash, and your editor context for your original feature stays untouched.git worktree add ../hotfix-workspace -b hotfix-bug mainThis instantly creates a sibling folder called hotfix-workspace , and bases it on main, and checks out a new branch called hotfix-bug .Now you can open that folder in a new editor window (or cd into it) and fix the bug. Your original editor window stays exactly as you left it.cd ../hotfix-workspace

# ...fix fix fix...

git add .

git commit -m "fix broken submit button"

git push origin hotfix-bugYou merge the pull request online just like before, and once it’s merged, you can simply delete the temporary folder.cd ../main-project

git worktree remove ../hotfix-workspaceThis is so much smoother! There’s zero risk of stash conflicts, there’s no editor disruption, and you can truly work in parallel.So… why now?For a really long time, worktrees were relatively unknown. Most developers had never heard of them, because either Git GUIs didn’t support them (or treated them as second-class citizens), or because they just usually followed the known pattern of feature branch, then work, then PR, then merge, then repeat.Now, our work as developers has changed. AI has made us work in parallel more than we ever have before in the history of software development. Developers run so many sessions in parallel, and “code review culture” is growing beyond “code writing culture.”Agents and humans can do more in parallel with worktrees. It’s the default mode for the GitHub Copilot app , and for many other modern tools.What’s the catch?Worktrees do solve a whole lot of issues, but there’s definitely some things to watch out for.Dependency bloat: each worktree folder requires its own copy of your project dependencies. If you’re running npm install or pip install across multiple of them, your computer might get very full, very quickly.Folder management: you have to delete the worktree folders, to avoid cluttering your parent directory over time. Apps like the GitHub Copilot app do often handle this for you, but it’s still something you might have to do yourself if you’re operating in the terminal yourself.Global .gitignore requirements: if you create worktree folders inside your main repo directory, you have to manually add them to .gitignore to not accidentally track them. You can make these worktrees outside of your main repo (and many apps do that by default), but it’s worth noting.One branch limits: Git prevents you from checking out the exact same branch in two different worktrees at the same time to prevent data corruption.How do I use worktrees in the GitHub Copilot app?Great question! What’s awesome is… they “just work” out of the box. When you open the app, there’s a dropdown that asks you where you want to run your new session on the home screen. The default is a new worktree.Then, once you kick off a new session, you can click the session name at the top of the app, and you’ll see the (fun!) generated name of your worktree, as well as the bath where it’s located, the project that worktree is for, and details about the changes that you’ve made.Easy peasy lemon squeezy!Should I use worktrees?I will give you the most senior developer answer I can: It depends! You might prefer working in one way or another. You might not do as much work in parallel and like the mental model of branches and stashing. You might only do worktrees from now on. You might want to do both!The world’s your oyster, and you can try them all in the GitHub Copilot app today.Tags:

Git

git worktrees

GitHub Copilot

GitHub Copilot appWritten byCassidy is senior director for developer advocacy here at GitHub. She enjoys building software, advising startups, and teaching developers how to build better. She has a weekly newsletter at cassidoo.co/newsletter where you can get her updates, practice coding problems, and a joke in your inbox!Related postsAI & ML

GitHub Copilot CLI for Beginners: Overview of common slash commandsGitHub Copilot CLI for Beginners: Learn how to use slash commands to control your terminal AI agent.AI & ML

Accelerating researchers and developers building multilingual AI with a new open datasetA new repository-level dataset, published on GitHub under CC0-1.0, helps researchers and developers discover multilingual developer content across READMEs, issues, and pull requests.AI & ML

How we made GitHub Copilot CLI more selective about delegationBetter orchestration, fewer handoffs, faster progress, without a single new knob.We do newsletters, tooDiscover tips, technical guides, and best practices in our biweekly newsletter just for devs.Your email address

抓取快照

用于解析和审计的抓取证据。

200 · text/html; charset=UTF-8

2026/06/17 10:57

e33654bfe3d8d55b802c29ad90d51cbd3a5d74b456272ae2079a447ef9832777

AI 输出

带验证状态的结构化模型输出。

article.summarize

deepseek-v4-flash · 有效

{"tags":["git","git worktrees","GitHub Copilot","GitHub Copilot app","parallel development","context switching"],"titleEn":"What are git worktrees, and why should I use them?","titleZh":"什么是 git worktrees,为什么我应该使用它们?","summaryEn":"Git worktrees allow developers to work on multipl...
article.classify

deepseek-v4-flash · 有效

{"relevant":true,"confidence":0.9,"primaryTopic":"software-engineering","secondaryTopics":["product-updates"]}

质量问题与日报引用

开放或已解决的问题,以及文章出现在每日日报中的记录。