هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
The quick answer
Step by step
- **Start from a fresh
main** —git pullfirst, then branch. Name branches by type and topic:feat/…,fix/…,chore/…. - Small commits, clear messages — the first line says what changes ("Limit login attempts to 5 per minute"), not "fix".
- Push and open the PR (quick answer).
--filltakes 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- Keep the branch up to date when
mainmoves — merge or rebase:
(Or rebase — see the rebase how-to.)
- Review loop: answer comments with new commits on the same branch; CI runs again on every push.
- Merge — choose one style for the repo:
| Style | Result |
|---|---|
| Squash | One commit per PR on main — clean history (common choice). |
| Merge commit | All commits plus a merge commit. |
| Rebase | All commits on top, no merge commit. |
- **Protect
main** (Settings → Rules): require a PR, required status checks, at least one approval, no force-push, optionally signed commits. - Clean up local branches after the merge:
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.
Common problems
| Problem | Cause | Fix |
|---|---|---|
rejected: protected branch on push to main | Direct 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 PR | Same lines changed on main. | Resolve locally (see the merge-conflict how-to). |
| Commits from another task in the PR | Branched from an old feature branch. | Always branch from fresh main; rebase onto main to clean. |
git branch -d refuses | Squash-merged branches look unmerged to Git. | git branch -D after you checked the PR is merged. |
| Huge PRs nobody reviews | Many changes at once. | Smaller PRs; one topic per PR. |
Go further
- Command pages: git, gh.
- Next how-tos: Rebase a branch on main, Resolve a Git merge conflict, Create a CI pipeline in GitHub Actions.
- Learn it: Git — Branches, Git — GitHub flow, Git — Pull requests, Git — Review, Git — Branch protection.
- Practise: Lab: branches, a real merge conflict and a protected main.
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.