Common Git Errors & Solutions
تجميعة لأشهر 10 رسائل خطأ بتقابل المبتدئين في Git و GitHub، وليه بتحصل، والحل المباشر لكل واحدة.
عشان بدل ما تضيع وقت في البحث كل مرة يطلعلك Error أحمر في الـ Terminal، تلاقي السبب والحل في ثانية هنا.
المفهوم ببساطة
معظم أخطاء Git سببها بسيط: يا إما رابط غلط (Repository not found)، يا إما صلاحيات (Permission denied)، يا إما GitHub عنده تعديلات جديدة لسه ما عملتلهاش pull قبل الـ push (Rejected push).
تابع تسلسل الخطوات العملي ده عشان تفهم إزاي الأوامر بتأثر على المشروع.
git statusتبدأ دايماً بفحص حالة المشروع الحالية قبل تنفيذ أي تغيير.
التطبيق العملي
اقرأ رسالة الخطأ في الجدول اللي تحت، وشوف الأمر المقابل ليها ونفذه بالهدوء. دايماً اقرأ سطر الـ hint اللي Git بيكتبه تحت الخطأ.
- 01لو ظهر Rejected Push: اعمل
git pull origin mainالأول وبعدهاgit push. - 02لو ظهر Detached HEAD: ارجع لبرانشك بأمر
git switch main. - 03لو ظهر Unrelated Histories: شغل
git pull origin main --allow-unrelated-histories.
Top 10 Git Errors & How to Fix Them
| Error / Message | Why It Happens | Quick Fix |
|---|---|---|
| Repository not found | Wrong URL, typo, or private repo without access | Check git remote -v and verify your GitHub access |
| Permission denied (publickey) | SSH key missing or not added to GitHub/ssh-agent | Run ssh -T git@github.com and re-add your .pub key |
| Authentication failed | Used GitHub password instead of a Personal Access Token | Generate a PAT in GitHub Settings or switch to SSH |
| nothing to commit, working tree clean | No new edits or files are already committed | Run git status; edit a file before adding/committing |
| failed to push some refs / non-fast-forward | GitHub has newer commits you do not have locally | Run git pull origin main first, then git push |
| Merge conflict in <file> | Two branches edited the same lines | Edit file, remove <<<<<<< markers, git add ., git commit |
| You are in "detached HEAD" state | Checked out a specific commit hash instead of a branch | Run git switch main (or git switch -c new-branch to save work) |
| refusing to merge unrelated histories | Local repo and GitHub repo started with separate initial commits | Run git pull origin main --allow-unrelated-histories |
| error: remote origin already exists | Tried git remote add origin when origin is already set | Use git remote set-url origin <url> instead |
شرح الأوامر بالتفصيل
git pull origin main --allow-unrelated-historiesبيدمج تاريخين مختلفين لما تربط مشروع محلي بريبو فيه ملفات على GitHub.
git pull origin main --allow-unrelated-historiesgit switch mainبيخرجك من حالة Detached HEAD ويرجعك للبرانش الأساسي.
git switch mainأخطاء شائعة خلي بالك منها
استخدام git push --force لحل رفض الـ Push
أمر --force بيمسح تاريخ GitHub وبيكتب مكانه، وده ممكن يضيع شغل زمايلك. اعمل pull الأول دايماً.
Git Labs
You've learned the concepts. Now let's put them into practice!