⏱️4 min read · 685 words
تختبر أسئلة المقابلة مع Git فهمك لمفاهيم التحكم في الإصدار، واستراتيجيات التفرع، والدمج مقابل إعادة الأساس، وسير العمل التعاوني. يغطي هذا الدليل أسئلة Git الأكثر شيوعًا لمقابلات مطوري البرامج في عام 2026.
أسئلة جيت الأساسية
1. ما الفرق بين git merge و git rebase؟
# merge: combines two branches, preserves full history
git checkout feature
git merge main
# Creates a merge commit — shows when branches diverged
# rebase: moves/replays commits on top of another branch
git checkout feature
git rebase main
# Linear history — as if feature branched off current main
# When to use merge:
# - Integrating feature branches to main (preserves history)
# - Public/shared branches (never rebase!)
# - When you want to see branch history
# When to use rebase:
# - Keeping feature branch up to date with main
# - Cleaning up local commits before PR
# - Squashing minor fix commits
# Golden rule: never rebase commits that have been pushed to shared branches
2. ما هو الرأس وما هو الرأس المنفصل؟
# HEAD = pointer to current commit (usually points to branch tip)
cat .git/HEAD # ref: refs/heads/main (pointing to main branch)
# Detached HEAD: HEAD points directly to a commit, not a branch
git checkout abc123 # checking out a specific commit
# HEAD is now at abc123 (detached)
# Any commits made won't belong to any branch!
# To save work in detached HEAD:
git checkout -b new-branch # create branch from current position
# Common cause: git checkout <tag> or git checkout <commit-hash>
3. شرح إعادة تعيين git مقابل git revert
# git reset: move HEAD backward (rewrites history)
git reset --soft HEAD~1 # undo commit, keep changes staged
git reset --mixed HEAD~1 # undo commit, keep changes unstaged (DEFAULT)
git reset --hard HEAD~1 # undo commit AND discard changes (DESTRUCTIVE)
# NEVER use --hard on shared branches!
# git revert: create a new commit that undoes a previous commit
git revert abc123 # safe for shared branches
# Creates commit: "Revert 'feature: add user auth'"
# Use reset for: local commits you want to undo
# Use revert for: commits already pushed to shared branches
4. ما هو git stash ومتى تستخدمه؟
# Temporarily save uncommitted changes
git stash push -m "WIP: half-done feature"
git stash list # see all stashes
git stash pop # apply latest + remove
git stash apply stash@{0} # apply without removing
git stash drop stash@{0} # delete a stash
# Stash specific files
git stash push -m "CSS fix" -- styles.css components/Button.css
# Include untracked files
git stash push -u -m "including new files"
# Common workflow:
# 1. Working on feature-A
# 2. Urgent fix needed on feature-B
# git stash (save feature-A work)
# git checkout feature-B
# ... fix ...
# git checkout feature-A
# git stash pop (restore feature-A work)
5. كيف يمكنك القضاء على الالتزامات المتعددة؟
# Interactive rebase — squash last 3 commits
git rebase -i HEAD~3
# Editor opens:
# pick abc123 feat: add login form
# pick def456 fix: correct validation
# pick ghi789 fix: typo in error message
# Change to:
# pick abc123 feat: add login form
# squash def456 fix: correct validation
# squash ghi789 fix: typo in error message
# Result: one clean commit with combined message
# Alternative: squash merge (GitHub/GitLab button)
# When merging PR, select "Squash and merge"
# All commits become one commit in main
6. ما هو اختيار الكرز؟
# Apply a specific commit from another branch
git log --oneline feature-branch # find the commit hash
git cherry-pick abc123 # apply just that commit
# Common use: apply a hotfix to multiple release branches
git checkout release/2.0
git cherry-pick fix/critical-bug-abc123
git checkout release/1.9
git cherry-pick fix/critical-bug-abc123
# Cherry-pick a range
git cherry-pick abc123..def456 # applies all commits in range
# If conflicts arise
git cherry-pick --continue # after resolving conflicts
git cherry-pick --abort # cancel cherry-pick
7. شرح استراتيجيات التفرع
GitFlow (complex, stable releases):
main — production
develop — integration
feature/xxx — feature branches
release/1.0 — release preparation
hotfix/xxx — urgent fixes
GitHub Flow (simple, continuous delivery):
main — always deployable
feature/xxx — short-lived feature branches
Pull Request → Code Review → Merge to main → Deploy
Trunk-Based Development (very short-lived branches):
main (trunk) — everyone commits daily
feature/xxx — max 1-2 days old, use feature flags
2026 recommendation: GitHub Flow or Trunk-Based for most teams
8. ما هو .gitignore ولماذا هو مهم؟
# .gitignore tells git which files to ignore
# Never commit:
# - Secrets/credentials (.env files!)
# - Dependencies (node_modules/, vendor/)
# - Build artifacts (dist/, __pycache__/)
# - OS files (.DS_Store, Thumbs.db)
# - IDE files (.idea/, .vscode/ — optional)
# Example .gitignore
*.env
*.env.*
node_modules/
dist/
build/
.DS_Store
__pycache__/
*.pyc
*.pem
*.key
# Already committed? Remove from tracking:
git rm --cached .env # stop tracking but keep file
git rm -r --cached dist/ # stop tracking directory
# Global gitignore (applies to all repos)
git config --global core.excludesfile ~/.gitignore_global
نجاح مقابلة Git: فهم نموذج التاريخ (الالتزامات والفروع وHEAD)، ومعرفة الفرق بين الدمج وإعادة الأساس ومتى يتم استخدام كل منهما، وشرح إعادة التعيين مقابل العودة بوضوح، وإظهار المعرفة بسير عمل الفريق (GitHub Flow، GitFlow). التدريب على المستودعات الحقيقية – قراءة تاريخ git أسهل من وصفه نظريًا.
🔗 Share this article
✍️ Leave a Comment