Git nâng cao
Amanda Crawford-Adamo
Software and Data Engineer
Lệnh Git Worktree
git worktree

Bảng này so sánh git worktree và git switch trong quy trình phát triển. $$
| Git Worktree | Git Switch |
|---|---|
| Nhiều nhánh hoạt động cùng lúc | Một nhánh hoạt động tại một thời điểm |
| Thư mục riêng biệt | Một thư mục làm việc |
| Không cần stash thay đổi | Có thể cần stash |
Tạo worktree mới từ <branch> vào thư mục <path>
git worktree add <path> <branch>
Ví dụ
Tạo worktree mới từ nhánh bugfix/data-validation vào thư mục ../etl-bugfix
git worktree add ../etl-bugfix bugfix/data-validation
git worktree list Ví dụ đầu ra
$ git worktree list
flight-pipeline a1b2c3d [main]
flight-pipeline-feature e4f5g6h [feature]
flight-pipeline-hotfix i7j8k9l [hotfix]
git worktree remove <path> Ví dụ đầu ra
$ git worktree remove flight-pipeline-hotfix
flight-pipeline-hotfix: deleted
Khi nên dùng:
Cân nhắc lại khi:
Khi dùng Git worktree, lưu ý:
Git nâng cao