Git Worktrees

एडवांस्ड Git

Amanda Crawford-Adamo

Software and Data Engineer

Git Worktree क्या है?

Git Worktree कमांड

git worktree
  • अपने workspace में कई branches को "checkout" कर सकते हैं।
  • repo checkout जैसा, लेकिन अधिक efficient
  • changes stash करने की ज़रूरत नहीं
  • development के दौरान branches बदलने की ज़रूरत नहीं

गोलों और लाइनों से बना एक नकली पेड़

एडवांस्ड Git

Git Worktree बनाम Git Switch

यह table development workflow में git worktree बनाम git switch की तुलना करता है. $$

Git Worktree Git Switch
Multiple active branches One active branch at a time
Separate directories Single working directory
No need to stash changes May require stashing
एडवांस्ड Git

Git Worktree बनाना

<branch> से नया worktree directory <path> में बनाएँ

git worktree add <path> <branch>

उदाहरण

bugfix/data-validation branch से ../etl-bugfix directory में नया worktree बनाएँ

git worktree add ../etl-bugfix bugfix/data-validation
एडवांस्ड Git

Worktrees सूचीबद्ध करना और हटाना

  • सभी active worktrees की सूची: git worktree list

उदाहरण आउटपुट

$ git worktree list
flight-pipeline            a1b2c3d [main]
flight-pipeline-feature    e4f5g6h [feature]
flight-pipeline-hotfix     i7j8k9l [hotfix]
  • किसी <path> से worktree हटाएँ: git worktree remove <path>

उदाहरण आउटपुट

$ git worktree remove flight-pipeline-hotfix
flight-pipeline-hotfix: deleted
एडवांस्ड Git

Git Worktrees कब उपयोग करें

कब उपयोग करें:

  • एक साथ कई features पर काम करना
  • ongoing work बिना बाधित किए urgent bug fixes संभालना
  • अलग-अलग branches पर parallel में tests चलाना
  • development जारी रखते हुए code reviews करना

कब पुनर्विचार करें:

  • disk space सीमित हो
  • projects में frequent updates और complex merge हों
एडवांस्ड Git

Git Worktrees के लिए Best Practices

Git worktrees इस्तेमाल करते समय ये tips ध्यान रखें:

  1. worktree directories के लिए clear naming conventions रखें
  2. workspace साफ रखने के लिए unused worktrees को नियमित रूप से prune करें
  3. खासकर बड़े projects में disk space का ध्यान रखें
  4. भ्रम से बचने के लिए short-lived parallel work में worktrees का उपयोग करें
एडवांस्ड Git

अभ्यास करते हैं!

एडवांस्ड Git

Preparing Video For Download...