git worktree 实际使用

Create

1.mkdir Connect_Backend_Database

2. cd Connect_Backend_Database

3. git clone url main

4. cd main

5. git worktree add -b v5 ../v5 origin/v5

6. git worktree add -b v6 ../v6 origin/v6

7.  git worktree list

 

git worktree add -b dev-bak ../dev-bak origin/develop

本地分支,本地文件夹,远程分支

Clean

1.cd Connect_Backend_Database/main

2. rm -rf ../v5

3. rm -rf ../v6

4. git worktree prune

5. git worktree list

 

https://git-scm.com/docs/git-worktree

You are in the middle of a refactoring session and your boss comes in and demands that you fix something immediately. You might typically use git-stash[1] to store your changes away temporarily, however, your working tree is in such a state of disarray (with new, moved, and removed files, and other bits and pieces strewn around) that you don’t want to risk disturbing any of it. Instead, you create a temporary linked working tree to make the emergency fix, remove it when done, and then resume your earlier refactoring session.

$ git worktree add -b emergency-fix ../temp master
$ pushd ../temp
# ... hack hack hack ...
$ git commit -a -m 'emergency fix for boss'
$ popd
$ git worktree remove ../temp

 

Git add a worktree from existing remote branch

If this existing north branch is useful, don't delete it! If it's already checked out in some existing work-tree, move to that work-tree and work on it there. If it's not checked out in some existing work-tree, you can make a new work-tree that does have it checked out; you just need to avoid using the -b flag (and the corresponding branch name):

git worktree add ../north north

 

 

文件夹重命名git的worktree不生效了

Check the content of your main repo/.git/worktrees

1.修改D:\Edenred\LISA\main\.git\worktrees\v5\gitdir文件中的路径

 2.修改D:\Edenred\LISA\v5\.git文件中的路径

 

Git add a worktree from existing remote branch

TL;DR: you probably wanted git worktree add ../north north

 git worktree add ../dev-bak dev-bak

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(808)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2019-04-30 GEEK UNINSTALLER
2015-04-30 ConcurrentDictionary<TKey, TValue>的AddOrUpdate方法
点击右上角即可分享
微信分享提示