Git switch Command
In this page:
git switch branch_name
git switch -c new_branch_name
git switch -
git switch से Basic Switching
git switch Git 2.23 में specifically पुराने, overloaded git checkout command के branch-switching आधे हिस्से को replace करने के लिए add किया गया था, branch changes को एक dedicated, कम error-prone command देते हुए एक narrower, clearer purpose के साथ।
उदाहरण: Basic Switching with git switch
git switch main
-c के साथ बनाना और Switch करना
git switch -c <new-branch> एक नई branch बनाता है और एक step में इस पर move करता है -- functionally git checkout -b जैसा ही outcome, बस नए, ज़्यादा explicit command name के तहत।
उदाहरण: Creating and Switching with -c
git switch -c feature-cart
वापस Switch करना और Tracking
git switch - आपको उस branch पर वापस jump करता है जिस पर आप अपने last switch से पहले थे, दो branches के बीच bounce करने के लिए एक तेज़ shortcut; git switch <remote-branch> सीधे एक remote branch की local tracking set up करता है।
उदाहरण: Switching Back and Tracking
git switch -
git switch origin-feature
--detach के साथ Detached HEAD
git checkout के उलट, जो एक commit hash दिए जाने पर चुपचाप detached HEAD में enter हो जाता है, git switch को वही करने के लिए explicit --detach flag चाहिए -- गलती से आपकी branch का track खोने से बचने के लिए एक deliberate design choice।
उदाहरण: Detached HEAD with --detach
git switch --detach a1b2c3d
Conflicting Local Changes Handle करना
अगर आपके uncommitted changes उस branch से overwrite हो जाएँगे जिस पर आप switch करने की कोशिश कर रहे हैं, git switch मना कर देता है और चुपचाप उन्हें discard या merge करने के बजाय एक error दिखाता है -- आगे बढ़ने के लिए आपको पहले commit, stash, या switch force करना होगा।
उदाहरण: Handling Conflicting Local Changes
git switch main
# error: Your local changes would be overwritten
git stash
git switch main
- एक file restore करने के लिए
git switch file.txtइस्तेमाल करना, जबकिswitchसिर्फ branches बदलता है;git restoreइस्तेमाल करें। - एक exist न करने वाली branch के लिए
git switch new-branchचलाना, जबकि एक बनाने के लिए-cचाहिए। - 2.23 से पहले Git version पर पुराने tutorials follow करना, जहाँ
git switchavailable नहीं है।
Chapter Quiz — Complete all 9 topics to unlock
0/9 topics done
Complete these topics first: