ورقة غش لأوامر Git

يتتبع Git التغييرات على ملفاتك كسلسلة من الالتزامات في مستودع. تغطي هذه الأوامر سير العمل اليومي: إنشاء مستودع، حفظ العمل، التفرع، الدمج والمشاركة مع مستودع بعيد. أبقِ هذه الورقة مفتوحة أثناء التعلم.

آخر تحديث:

الأمروظيفته
git initCreate a new, empty Git repository in the current directory.
git cloneDownload a remote repository and its full history to your machine.
git statusShow changed, staged and untracked files in the working tree.
git addStage changes (files) to be included in the next commit.
git commitRecord staged changes as a new commit with a message.
git logDisplay the commit history of the repository.
git diffShow unstaged or staged differences between states.
git branchList, create or delete branches in the repository.
git checkout / switchSwitch branches or restore files (switch is the modern command).
git mergeJoin another branch's history into the current branch.
git rebaseReapply commits on top of another base commit, rewriting history.
git pullFetch from a remote and merge the changes into the current branch.
git pushUpload local commits to a remote repository.
git stashTemporarily shelve uncommitted changes to reapply later.
git remoteManage the set of remote repositories you track.

ملاحظات

الأسئلة الشائعة

ما الفرق بين merge وrebase؟
يجمع merge التواريخ عبر التزام جديد له أبوان. أمّا rebase فيعيد تشغيل التزاماتك فوق فرع آخر، منتجًا تاريخًا خطيًا لكنه يعيد كتابة معرّفات الالتزام.
كيف أتراجع عن التزام؟
استخدم 'git revert <commit>' لإضافة التزام جديد يلغي التغيير (آمن، يحفظ التاريخ المشترك). أما 'git reset' فيعيد كتابة التاريخ ولا يجب استخدامه على الفروع المشتركة.
ما الفرق بين git pull وgit fetch؟
يجلب fetch الالتزامات والمراجع من مستودع بعيد دون المساس بشجرة العمل. أمّا pull فيجلب ثم يدمج أو يعيد ترتيب تلك التغييرات في فرعك الحالي.
متى أستخدم git stash؟
يضع stash التغييرات غير الملتزمة جانبًا مؤقتًا لتتمكن من تبديل الفروع أو السحب بوضوح، ثم تستعيدها لاحقًا بـ 'git stash pop'.