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 কমিট না-করা পরিবর্তনগুলো অস্থায়ী সরিয়ে রাখে, যাতে আপনি পরিষ্কারভাবে ব্রাঞ্চ বদলাতে বা পুল করতে পারেন, পরে 'git stash pop' দিয়ে ফিরিয়ে আনতে পারেন।