Git कमांड चीटशीट
Git फ़ाइलों के बदलावों को रिपॉज़िटरी में कमिट की एक शृंखला के रूप में ट्रैक करता है। ये कमांड दैनिक कार्यप्रवाह कवर करते हैं: रिपो बनाना, काम सेव करना, ब्रांच बनाना, मर्ज करना और रिमोट से शेयर करना। सीखते समय शीट खुली रखें।
| कमांड | क्या करता है |
|---|---|
| git init | Create a new, empty Git repository in the current directory. |
| git clone | Download a remote repository and its full history to your machine. |
| git status | Show changed, staged and untracked files in the working tree. |
| git add | Stage changes (files) to be included in the next commit. |
| git commit | Record staged changes as a new commit with a message. |
| git log | Display the commit history of the repository. |
| git diff | Show unstaged or staged differences between states. |
| git branch | List, create or delete branches in the repository. |
| git checkout / switch | Switch branches or restore files (switch is the modern command). |
| git merge | Join another branch's history into the current branch. |
| git rebase | Reapply commits on top of another base commit, rewriting history. |
| git pull | Fetch from a remote and merge the changes into the current branch. |
| git push | Upload local commits to a remote repository. |
| git stash | Temporarily shelve uncommitted changes to reapply later. |
| git remote | Manage the set of remote repositories you track. |
टिप्पणियाँ
- ज़्यादातर कमांड फ़्लैग लेते हैं (जैसे -m संदेश के लिए, -a सभी के लिए); पूरी सूची 'git help <कमांड>' से देखें।
- ब्रांच नाम सस्ते और फेंकने योग्य होते हैं — फ़ीचर ब्रांच पर बार-बार कमिट करें, फिर main में मर्ज करें।
- rebase या reset जैसे विनाशकारी कमांड से पहले सुनिश्चित करें कि आपका काम कमिट या stash हो गया है।
सामान्य प्रश्न
- merge और rebase में क्या अंतर है?
- merge एक नए कमिट (जिसके दो पैरेंट होते हैं) से इतिहास मिलाता है। rebase आपके कमिट को दूसरी ब्रांच के ऊपर फिर चलाता है, जिससे लीनियर इतिहास बनता है पर कमिट ID बदल जाते हैं।
- किसी कमिट को अनडू कैसे करें?
- 'git revert <कमिट>' चलाएँ, जो बदलाव पलटने वाला नया कमिट जोड़ता है (सुरक्षित, शेयर किया गया इतिहास बरकरार)। 'git reset' इतिहास राइट करता है, इसे शेयर ब्रांच पर न चलाएँ।
- git pull और git fetch में अंतर?
- fetch रिमोट से कमिट और रेफ़ बिना वर्किंग ट्री छुए डाउनलोड करता है। pull पहले fetch करता है, फिर उन बदलावों को मर्ज या रीबेस करके मौजूदा ब्रांच में लाता है।
- git stash कब इस्तेमाल करें?
- stash अनकमिट बदलावों को अस्थायी रूप से अलग रखता है ताकि आप स्वच्छ रूप से ब्रांच बदल या pull कर सकें, बाद में 'git stash pop' से वापस लाएँ।