متقدم
البحث فيأدلة «كيف»
طريقة البحث
  • اكتب المهمة بكلماتك (find port، open firewall، disk full) أو الصق رسالة الخطأ بين علامتي تنصيص.
  • اختر «الإجابة السريعة» لترى الأوامر فقط، أو مجالًا لتبقى في مجال واحد.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

كيف 154Git · CI/CD

How to work with branches and pull requests

In a team nobody commits directly to main. Each change goes on a branch, is opened as a pull request (PR), is checked by CI and reviewed, and only then merged. This how-to is the daily loop: create a branch, push it, open the PR from the terminal, keep it up to date, merge it, clean up — plus the branch rules that make it safe.

  • 5 الدروس
  • 2 الأوامر

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

154.1

The quick answer

git switch main && git pull
git switch -c fix/login-rate-limit
git add -A && git commit -m "Limit login attempts to 5 per minute"
git push -u origin fix/login-rate-limit
gh pr create --fill --base main
gh pr checks --watch
gh pr merge --squash --delete-branch

الأوامر في هذا الدرس

154.2

Step by step

  1. **Start from a fresh main** — git pull first, then branch. Name branches by type and topic: feat/…, fix/…, chore/….
  2. Small commits, clear messages — the first line says what changes ("Limit login attempts to 5 per minute"), not "fix".
  3. Push and open the PR (quick answer). --fill takes the title/body from the commits; add reviewers and labels:
gh pr create --base main --title "Limit login attempts" --body-file pr.md --reviewer alice --label security
  1. Keep the branch up to date when main moves — merge or rebase:
git fetch origin
git merge origin/main
git push

(Or rebase — see the rebase how-to.)

  1. Review loop: answer comments with new commits on the same branch; CI runs again on every push.
gh pr view --web
gh pr checks
  1. Merge — choose one style for the repo:
StyleResult
SquashOne commit per PR on main — clean history (common choice).
Merge commitAll commits plus a merge commit.
RebaseAll commits on top, no merge commit.
  1. **Protect main** (Settings → Rules): require a PR, required status checks, at least one approval, no force-push, optionally signed commits.
  2. Clean up local branches after the merge:
git switch main && git pull
git branch -d fix/login-rate-limit
git fetch --prune

الأوامر في هذا الدرس

154.3

Check that it worked

The PR shows green checks and an approval, it merges into main, the branch is deleted, and git log --oneline -3 on main shows your change.

الأوامر في هذا الدرس

154.4

Common problems

ProblemCauseFix
rejected: protected branch on push to mainDirect pushes are blocked (good).Push a branch and open a PR.
PR shows "This branch is out-of-date"main moved; rule requires up-to-date branches.Merge/rebase origin/main and push.
Conflicts in the PRSame lines changed on main.Resolve locally (see the merge-conflict how-to).
Commits from another task in the PRBranched from an old feature branch.Always branch from fresh main; rebase onto main to clean.
git branch -d refusesSquash-merged branches look unmerged to Git.git branch -D after you checked the PR is merged.
Huge PRs nobody reviewsMany changes at once.Smaller PRs; one topic per PR.

الأوامر في هذا الدرس

154.5

Go further

1Why branch from a freshly pulled main?

So your PR contains only your change, with the fewest conflicts.

2What does "squash merge" put on main?

One commit for the whole pull request.

الأوامر في هذا الدرس

كل الأوامر في هذا الفصل