Common Git Errors & Solutions

تجميعة لأشهر 10 رسائل خطأ بتقابل المبتدئين في Git و GitHub، وليه بتحصل، والحل المباشر لكل واحدة.

ليه الدرس ده مهم؟

عشان بدل ما تضيع وقت في البحث كل مرة يطلعلك Error أحمر في الـ Terminal، تلاقي السبب والحل في ثانية هنا.

المفهوم ببساطة

معظم أخطاء Git سببها بسيط: يا إما رابط غلط (Repository not found)، يا إما صلاحيات (Permission denied)، يا إما GitHub عنده تعديلات جديدة لسه ما عملتلهاش pull قبل الـ push (Rejected push).

محاكاة خطوات: Common Git Errors & Solutions

تابع تسلسل الخطوات العملي ده عشان تفهم إزاي الأوامر بتأثر على المشروع.

$git status
Working Dir
فحص التغييرات
Local Repo
مستعد
Remote (GitHub)
متصل
برتقالي: شغال هنا دلوقتيأخضر: خلص وجاهزرمادي: مستني دوره

تبدأ دايماً بفحص حالة المشروع الحالية قبل تنفيذ أي تغيير.

1 / 3

التطبيق العملي

اقرأ رسالة الخطأ في الجدول اللي تحت، وشوف الأمر المقابل ليها ونفذه بالهدوء. دايماً اقرأ سطر الـ hint اللي Git بيكتبه تحت الخطأ.

  1. 01لو ظهر Rejected Push: اعمل git pull origin main الأول وبعدها git push.
  2. 02لو ظهر Detached HEAD: ارجع لبرانشك بأمر git switch main.
  3. 03لو ظهر Unrelated Histories: شغل git pull origin main --allow-unrelated-histories.

Top 10 Git Errors & How to Fix Them

Error / MessageWhy It HappensQuick Fix
Repository not foundWrong URL, typo, or private repo without accessCheck git remote -v and verify your GitHub access
Permission denied (publickey)SSH key missing or not added to GitHub/ssh-agentRun ssh -T git@github.com and re-add your .pub key
Authentication failedUsed GitHub password instead of a Personal Access TokenGenerate a PAT in GitHub Settings or switch to SSH
nothing to commit, working tree cleanNo new edits or files are already committedRun git status; edit a file before adding/committing
failed to push some refs / non-fast-forwardGitHub has newer commits you do not have locallyRun git pull origin main first, then git push
Merge conflict in <file>Two branches edited the same linesEdit file, remove <<<<<<< markers, git add ., git commit
You are in "detached HEAD" stateChecked out a specific commit hash instead of a branchRun git switch main (or git switch -c new-branch to save work)
refusing to merge unrelated historiesLocal repo and GitHub repo started with separate initial commitsRun git pull origin main --allow-unrelated-histories
error: remote origin already existsTried git remote add origin when origin is already setUse git remote set-url origin <url> instead

شرح الأوامر بالتفصيل

git pull origin main --allow-unrelated-histories

بيدمج تاريخين مختلفين لما تربط مشروع محلي بريبو فيه ملفات على GitHub.

git pull origin main --allow-unrelated-histories
git switch main

بيخرجك من حالة Detached HEAD ويرجعك للبرانش الأساسي.

git switch main

أخطاء شائعة خلي بالك منها

COMMON MISTAKE

استخدام git push --force لحل رفض الـ Push

أمر --force بيمسح تاريخ GitHub وبيكتب مكانه، وده ممكن يضيع شغل زمايلك. اعمل pull الأول دايماً.

Git Labs

You've learned the concepts. Now let's put them into practice!