کدنامهمرجع‌های مهندسی نرم‌افزار، به فارسی
گیت · فصل ۱۳Git · Chapter 13

استراتژی شاخه‌بندی

Branching strategies: trunk-based, GitHub Flow, and Git Flow

Git ساختن شاخه را ارزان کرده، اما فاصله‌گرفتن آدم‌ها از هم رایگان نیست. این فصل به‌جای انتخاب یک اسم محبوب، می‌پرسد تیم شما چقدر زود ادغام می‌کند، چطور منتشر می‌کند و چه چیزی را باید کنترل کند.

Imagine a five-person team with twelve feature branches, some alive for two weeks. A small change now has to be coordinated across several branches, and nobody is sure which version is ready to release. Creating a Git branch is cheap; is keeping people apart for a long time cheap too?

۱۳بخشsections
۸۵دقیقهminزمان مطالعهreading time
۱۸تمرین با پاسخsolved exercises
۵نمودارdiagrams

شاخه‌ها ارزان‌اند؛ فاصله‌ای که می‌سازند نهBranches are cheap; the distance they create is not

فصل ۵ نشان داد شاخه در Git یک اشاره‌گر سبک به commit است، نه یک کپی کامل از پوشه. پس چرا دوازده شاخهٔ زنده برای تیم دردسر شده؟ هزینهٔ اصلی روی دیسک نیست؛ در تفاوت‌هایی است که آدم‌ها باید بعداً کنار هم بگذارند.

Chapter 5 showed that a Git branch is a lightweight pointer to a commit, not a full copy of the directory. So why are twelve active branches hurting this team? The main cost is not on disk; it is the divergence people must reconcile later.

هر شاخه‌ای که کار مستقل روی آن ادامه دارد، ممکن است از شاخهٔ اصلی commitهای تازه را نبیند. تغییر نام یک تابع، جابه‌جایی فایل یا اصلاح یک قرارداد API می‌تواند در این مدت در جای دیگری اتفاق بیفتد. وقتی دو مسیر دوباره merge می‌شوند، Git بخش‌هایی را که می‌تواند ترکیب می‌کند؛ اما نمی‌داند دو تغییر از نظر محصول با هم سازگارند یا نه. فصل‌های ۶ و ۷ ابزار ادغام را یاد دادند؛ این فصل دربارهٔ کم‌کردن هزینه و انتخاب زمان ادغام است.

Any branch with ongoing independent work may miss new commits on the main line. A function rename, file move, or API contract change can happen elsewhere in the meantime. When the paths meet again, Git combines what it can, but it cannot know whether the two changes make sense together as a product. Chapters 6 and 7 taught the integration tools; this chapter is about reducing integration cost and choosing when to integrate.

Long-lived branches diverge and later require a costly integration time passes while branches diverge lateintegration shared basemainfeature more divergence can mean more conflicts and more compatibility questions
نمودار ۱ — دو شاخه از یک پایه دور می‌شوند و دیرتر دوباره به هم می‌رسند. خط‌ها رابطهٔ رابطهٔ والدها را نشان می‌دهند؛ قاب آخر «هزینهٔ تضمینی» نیست، یادآور کاری است که تیم باید هنگام ادغام انجام دهد.
Diagram 1 — Two branches move away from a common base and meet later. The lines show ancestry; the final box is not a guaranteed cost, but a reminder of the work the team must do at integration time.

این به معنی «هر merge سخت است» نیست. Git می‌تواند merge را بدون تعارض انجام دهد، اما تست یکپارچه، ترتیب انتشار و رفتار ترکیب‌شده هنوز مسئولیت ماست. سؤال بهتر این است: فاصلهٔ شاخه‌ها چقدر باشد که هزینهٔ هماهنگی و ریسک تغییر، از سود جداسازی بیشتر نشود؟

This does not mean every merge is difficult. Git may merge without conflicts, but integration tests, release order, and combined behavior remain our responsibility. A better question is: how far apart can branches get before coordination cost and change risk outweigh the value of isolation?

قبل از اسم الگوها، مسئلهٔ تیم را اندازه بگیرBefore naming models, measure the team's problem

اگر فقط بپرسیم «Git Flow بهتر است یا trunk-based؟» هنوز اطلاعات کافی نداریم. اول ببینیم تیم چه چیزی را باید هماهنگ کند. یک محصول وب که روزی چند بار منتشر می‌شود، مسئله‌ای متفاوت از کتابخانه‌ای دارد که دو نسخهٔ قبلی‌اش هنوز پشتیبانی می‌شوند.

If we only ask “Is Git Flow or trunk-based better?”, we do not yet have enough information. First look at what the team must coordinate. A web product deployed several times a day has a different problem from a library that still supports two previous versions.

بُعدDimensionسؤال واقعیPractical questionچرا مهم است؟Why it matters
عمر شاخهBranch lifetimeتغییر معمولاً چند ساعت، چند روز یا چند هفته جدا می‌ماند؟Does ordinary work stay separate for hours, days, or weeks?هرچه جدایی بیشتر، احتمال عقب‌ماندن و ادغام پرهزینه‌تر می‌شود؛ نه به‌صورت جادویی یا قطعی، بلکه چون تغییرهای بیشتری باید هماهنگ شوند.Longer separation creates more opportunity to fall behind and a larger integration task—not by magic, but because more changes must be coordinated.
بسامد ادغام و انتشارIntegration and release cadenceتغییرها را چند بار با خط اصلی جمع می‌کنید؟ انتشار مستقل است یا دسته‌ای؟How often do you integrate? Are releases independent or batched?شاخه‌بندی باید جریان واقعی ساخت و انتشار را منعکس کند، نه اینکه خودش یک تقویم ساختگی بسازد.Branching should reflect the actual build and release flow, not invent a calendar of its own.
CI و تستCI and testsآیا تغییر پیش از ادغام، سریع و قابل‌اعتماد بررسی می‌شود؟Can a change be checked quickly and reliably before integration?ادغام پرتکرار بدون بازخورد مناسب، عیب را زودتر به همه می‌رساند؛ CI خوب زمان کشف را کم می‌کند.Frequent integration without useful feedback spreads a defect sooner; effective CI shortens the time to discover it.
قابلیت flag و تغییر ناتمامFeature flags and unfinished workمی‌شود کد را ادغام کرد بی‌آنکه قابلیت برای همه فعال شود؟Can code be integrated without exposing the feature to everyone?flag می‌تواند جدایی شاخه را کوتاه کند؛ اما flagهای بی‌صاحب خودشان بدهی و حالت‌های تستی تازه می‌سازند.A flag can shorten branch separation, but neglected flags create debt and additional test combinations.
نسخه‌های پشتیبانی‌شدهSupported production versionsآیا باید نسخه‌های قدیمی را جداگانه patch کنیم؟Must older releases continue receiving patches?گاهی شاخهٔ نسخه‌ انتشار لازم است؛ اما وجود شاخه به‌تنهایی سیاست انتخاب patch را تعریف نمی‌کند.A release branch may be useful, but its existence alone does not define which fixes go where.
هماهنگی انتشار و اصلاح فوریRelease and hotfix coordinationچه کسی نسخه را تثبیت می‌کند و رفع فوری چطور به خط بعدی می‌رسد؟Who stabilizes a release, and how does an urgent fix reach the next line?باید مقصد اصلاح فوری و روش بازگرداندن آن به توسعهٔ بعدی روشن باشد.The hotfix destination and its route back to ongoing development must be clear.
اندازه و شکل تیم/مخزنTeam and repository shapeیک تیم روی یک سرویس است یا چند تیم و چند خط انتشار؟Is one team working on one service, or are there several teams and release lines?تعداد شاخهها پاسخ مستقیمی برای تعداد تیم‌ها نیست؛ مالکیت، مرز انتشار و معماری مهم‌ترند.The number of branches is not a direct proxy for the number of teams; ownership, release boundaries, and architecture matter more.
نیاز به کنترل رسمیExplicit release controlآیا تأیید، توقف انتشار یا ثبت مسیر ممیزی الزام است؟Are approvals, release freezes, or an auditable path mandatory?این کنترل‌ها را می‌توان با CI، حفاظت شاخه و فرایند انتشار پیاده کرد؛ لزوماً به انشعاب‌های طولانی نیاز ندارند.CI, branch protection, and release procedures can provide these controls; long-lived branches are not automatically required.
Branching choices depend on a set of team and product dimensions team constraints integration cadenceoften ↔ batched release shapecontinuous ↔ versions safety netCI, review, flags choose a fitting policy; revisit it
نمودار ۲ — نام الگو خروجی مستقیم یک بُعد نیست. بسامد ادغام، انتشار و توان بررسی با هم انتخاب را شکل می‌دهند؛ بعد از تغییر تیم یا محصول، این تصمیم را دوباره می‌سنجیم.
Diagram 2 — No single dimension determines the model. Cadence, release shape, and review capability jointly shape the choice; revisit it when the team or product changes.

برای trunk-based، یک شاخهٔ نسخه‌ انتشار موقت با کاربرد روشن الزاماً تناقض نیست؛ برای نمونه، تیم می‌تواند از trunk نسخه را آماده کند و مدت کوتاهی آن را تثبیت کند. مرز اصلی این است که آیا شاخه‌های طولانیِ توسعه به مسیر عادی تبدیل شده‌اند یا نه. هیچ جدول امتیازی جای گفت‌وگوی تیم دربارهٔ پاسخ همین سؤال‌ها را نمی‌گیرد.

A temporary release branch with a clear purpose does not automatically contradict trunk-based development; for example, a team may cut one from trunk to stabilize a release briefly. The key question is whether long-lived development branches have become the normal path. No scoring table can replace the team's discussion of these questions.

trunk-based: زود ادغام کن، بازخورد را زود بگیرTrunk-based: integrate early and get feedback early

در تیم پنج‌نفره، شاید قابلیت شاخهها هفته‌ها از هم خبر نداشته باشند. در trunk-based، مرکز یکپارچه‌سازی همان `main` یا trunk است و تغییرها مرتب به آن برمی‌گردند. بعضی تیم‌های کوچک مستقیم commit می‌کنند؛ تیم‌های دیگر برای بازبینی و CI شاخهٔ کوتاه‌عمر می‌سازند. «همه مستقیم روی main بنویسند» تعریف این روش نیست.

In the five-person team, feature branches may go weeks without seeing one another. In trunk-based development, `main` or trunk is the integration center and changes return to it frequently. Some small teams commit directly; others use short-lived branches for review and CI. “Everyone writes directly to main” is not the definition.

به‌جای کارکردن روی یک قابلیت کامل تا روز انتشار، تغییر را به قدم‌های کوچک و سازگار می‌شکنیم. هر قدم سریع ساخته و تست می‌شود؛ اگر قابلیت هنوز آمادهٔ استفاده نیست، گاهی قابلیت flag کمک می‌کند کد در trunk باشد اما رفتار برای کاربران فعال نشود. flag خودکار امنیت نمی‌سازد: باید حالت روشن و خاموش را تست کرد و flag موقت را بعداً حذف کرد.

Instead of developing an entire feature until release day, we split it into small, compatible steps. Each step is built and tested quickly. If a feature is not ready for users, a feature flag may let the code live on trunk while the behavior stays disabled. A flag is not automatic safety: test both states and remove temporary flags later.

Short change branches return quickly to the shared trunk with CI feedback shared integration line: main / trunk review + CI review + CI small stepsintegrated direct commits are also possible under an explicit team policy
نمودار ۳ — شاخه‌های کوتاه برای بازبینی/CI از trunk جدا می‌شوند و زود به همان خط برمی‌گردند؛ نقطه‌ها زمان و ترتیب دقیق را تضمین نمی‌کنند. گزینهٔ commit مستقیم هم به سیاست و اندازهٔ تیم بستگی دارد.
Diagram 3 — Short branches split from trunk for review/CI and return quickly to the same line; the dots do not promise exact timing or ordering. Direct commits are also a policy choice that depends on the team.
چیزی که این الگو لازم داردWhat this model needs

یک trunk قابل‌اعتماد، CI با بازخورد به‌موقع، تغییرهای کوچک و راهی برای ادغام امن قابلیتهای ناتمام. اگر تست‌ها ساعت‌ها طول می‌کشند یا ساخت قرمز می‌تواند روزها بماند، اول باید برای این ریسک برنامه داشته باشیم؛ صرفاً کوتاه‌کردن عمر شاخه کافی نیست.

A trustworthy trunk, timely CI feedback, small changes, and a way to integrate unfinished features safely. If tests take hours or a broken build can remain broken for days, the team needs a plan for that risk; merely shortening branch lifetime is not enough.

طرف دیگر انتخاب هم واقعی است: ادغام پرتکرار، مشکل ناسازگاری را زودتر آشکار می‌کند، اما بار CI و مسئولیت سبز نگه‌داشتن trunk را بالا می‌برد. شاخهٔ کوتاه‌عمر هم هنوز ممکن است تعارض داشته باشد؛ فقط معمولاً فاصلهٔ زمانی کمتری برای انباشته‌شدن تغییرها دارد.

The other side of the trade-off is real: frequent integration exposes incompatibility sooner, but increases CI load and the responsibility to keep trunk green. A short-lived branch can still conflict; it simply has less time to accumulate unrelated change.

GitHub Flow: مسیر سبکِ شاخه و PRGitHub Flow: a lightweight branch-and-PR path

حالا فرض کن تیم برای هر تغییر به بازبینی همکار نیاز دارد. GitHub Flow مسیر ساده‌ای برای آن می‌دهد: شاخه بساز، commit و push کن، PR باز کن، بازخورد و بررسیها را بگیر، merge کن و شاخهٔ تمام‌شده را حذف کن. این گردش کار میزبانی‌شده است؛ قانون تازه‌ای در مدل شیءهای Git نیست.

Now suppose every change needs a teammate's review. GitHub Flow offers a lightweight path: create a branch, commit and push, open a PR, get feedback and checks, merge, then delete the finished branch. It is a hosted collaboration workflow, not a new rule in Git's object model.

GitHub Flow takes a change from branch through pull request review and checks to merge branchsmall change push + PRask for review review + checksrevise if needed mergethen delete branch protected target branchchecks / review follow repo policy
نمودار ۴ — PR درخواست همکاری است؛ بررسی و تأیید وقتی مانع ادغام می‌شوند که مخزن آن‌ها را الزام کرده باشد. نمودار به رفتار دقیق یک پلتفرم یا روش merge خاص وابسته نیست.
Diagram 4 — A PR is a request for collaboration; checks and approvals block merging only when the repository requires them. This diagram does not assume a particular platform implementation or merge method.

در راهنمای رسمی GitHub Flow، جریان با شاخه کوتاه و توصیفی، commit/push، PR برای بازخورد، رسیدگی به نظرها، merge بعد از تأیید و پاک‌کردن شاخه ادغام‌شده توضیح داده می‌شود. بررسی یا تعداد بازبینیها به تنظیم مخزن بستگی دارد؛ PR به‌تنهایی تضمین نمی‌کند چیزی تست شده باشد. دیگر میزبان‌ها هم گردش‌های شبیه به آن دارند، ولی نام و جزئیات UI ممکن است فرق کند.

GitHub's official GitHub Flow guide describes a short, descriptive branch, commits and pushes, a PR for feedback, addressing review comments, merging after approval, and deleting the merged branch. Checks and review counts depend on repository settings; a PR alone does not guarantee that anything was tested. Other hosts offer similar workflows, though UI names and details vary.

یک سؤال مهم دربارهٔ انتشار باقی می‌ماند: merge شد، پس چه کسی یا چه چیزی نسخه را منتشر می‌کند؟ بعضی تیم‌ها با هر merge به main انتشار می‌دهند؛ بعضی انتشار را دستی یا در بازه‌های مشخص انجام می‌دهند. GitHub Flow خودش به‌تنهایی روش استقرار را تحمیل نمی‌کند.

One release question remains: it merged, so who or what deploys it? Some teams deploy every merge to main; others deploy manually or on a schedule. GitHub Flow does not itself prescribe a deployment model.

Git Flow: شاخه‌ها با نقش انتشار تعریف می‌شوندGit Flow: branches have release-oriented roles

برای تیمی که چند خط کار و انتشار نسخه‌ای دارد، مسیر سبک شاخه→PR شاید به‌تنهایی برنامهٔ انتشار را نشان ندهد. مدل کلاسیک Git Flow این نقش‌ها را جدا می‌کند: `main` برای نسخه‌های منتشرشده، `develop` برای جمع‌شدن کار نسخهٔ بعد، `feature/*` برای قابلیت، `release/*` برای تثبیت و `hotfix/*` برای رفع فوری نسخهٔ زنده.

For a team with several work and release lines, a lightweight branch-to-PR path may not show the release plan by itself. The classic Git Flow model assigns distinct roles: `main` for released versions, `develop` for assembling the next release, `feature/*` for features, `release/*` for stabilization, and `hotfix/*` for urgent fixes to a live version.

Classic Git Flow has main and develop lines plus feature, release, and hotfix branches main · released linedevelop · next release featurereleasehotfix release / hotfix fixes must return to ongoing development
نمودار ۵ — نمای ساده‌شدهٔ مدل کلاسیک: قابلیت به develop می‌پیوندد؛ نسخه‌ انتشار به خط نسخه و دوباره به develop می‌رسد؛ اصلاح فوری از نسخهٔ زنده شروع می‌شود و باید وارد خط‌های فعال بعدی هم بشود. نمودار همهٔ جزئیات و سیاست‌های امروزی را نمایش نمی‌دهد.
Diagram 5 — A simplified view of the classic model: features join develop; a release reaches the release line and then develop; a hotfix starts from the live version and must also reach active future lines. The diagram omits details and does not prescribe today's policies.

برای نسخه‌ انتشار، تیم وقتی develop به ترکیب موردنظر رسید `release/*` می‌سازد، کارهای تثبیت و نسخه‌گذاری را آنجا انجام می‌دهد، خروجی را در main با نسخهٔ مشخص tag می‌کند و اصلاح‌های نسخه‌ انتشار را به develop هم برمی‌گرداند. برای اصلاح فوری، نقطهٔ شروع نسخهٔ واقعاً منتشرشده است؛ بعد از آماده‌شدن، تغییر باید هم نسخهٔ زنده را اصلاح کند و هم به خط توسعه برگردد. اگر شاخهٔ نسخه‌ انتشار باز است، مسیر برگشت باید طبق سیاست تیم مشخص شود تا fix گم نشود.

For a release, the team cuts `release/*` once develop contains the intended scope, performs stabilization and versioning there, tags the released result on main, and brings release fixes back to develop. A hotfix starts from the actually released version; once ready, it must fix the live line and return to ongoing development. If a release branch is open, the team must define the back-merge path so the fix is not lost.

این مدل می‌تواند برای محصول نسخه‌ای، چند نسخهٔ پشتیبانی‌شده یا هماهنگی تثبیت رسمی مفید باشد. بهایش هم روشن است: شاخه‌ها و mergeهای بیشتر، تصمیم‌های بیشتر دربارهٔ اینکه هر fix کجا برود، و احتمال عقب‌ماندن خط‌ها از هم. اگر عملاً همیشه main را منتشر می‌کنی و نسخهٔ بعدی جداگانه‌ای نداری، develop و نسخه‌ انتشارهای دائمی ممکن است تشریفات بی‌فایده بسازند.

This model can help with versioned products, several supported versions, or formal stabilization. Its costs are also real: more branches and merges, more decisions about where each fix belongs, and more chances for lines to drift. If you always release main and have no separately assembled next version, permanent develop and release branches may add ceremony without value.

نام‌گذاری شاخهها قابلیت ویژه‌ای در Git ایجاد نمی‌کند؛ همهٔ آن‌ها همان شاخههای معمولی‌اند. نقش را توافق تیم تعریف می‌کند. اگر می‌خواهی مسیر دقیق مدل اولیه را ببینی، مقالهٔ اصلی Vincent Driessen را بخوان؛ Git Flow کلاسیک را با همین فرض ببین، نه به‌عنوان پیش‌فرض Git یا الزام هر مخزن.

Branch names do not create special behavior in Git; they are ordinary branches. The team agreement gives them their roles. For the original model, see Vincent Driessen's original article; treat classic Git Flow as a model, not a Git default or a requirement for every repository.

سه الگو را با نیاز مقایسه کن، نه با محبوبیتCompare the models by need, not popularity

هیچ‌کدام وعدهٔ خودکارِ کیفیت، تست یا انتشار امن نمی‌دهند. تفاوت اصلی در این است که خط ادغام کجا قرار می‌گیرد، کار چند وقت جدا می‌ماند و انتشار چطور کنترل می‌شود.

None automatically promises quality, tests, or safe releases. The main differences are where integration happens, how long work stays separate, and how releases are controlled.

الگوModelمرکز ادغامIntegration centerشکل معمول شاخهTypical branchesجایی که می‌درخشد / بهایشWhere it helps / what it costs
trunk-basedیک trunk مشترک؛ گاهی مستقیم و گاهی با شاخهٔ کوتاه برای بررسیOne shared trunk; direct integration or short review branchesجدایی کوتاه، ادغام پرتکرار، گاهی نسخه‌ انتشار شاخه موقتShort separation, frequent integration, sometimes a temporary release branchبازخورد زود؛ نیازمند CI قابل‌اعتماد، تغییر کوچک و مراقبت از trunkEarly feedback; needs reliable CI, small changes, and care for trunk
GitHub Flowشاخهٔ پیش‌فرض میزبان از راه PRThe host's default branch through PRsشاخهٔ تغییر، commit/push، بازبینی/check، mergeChange branch, commits/push, review/checks, mergeمسیر بازبینی ساده و روشن؛ جزئیات الزام‌ها و استقرار را مخزن تعیین می‌کندA clear review path; the repository defines requirements and deployment details
Git Flowdevelop برای نسخهٔ بعد؛ main برای انتشارdevelop for the next release; main for releasesقابلیت، نسخه‌ انتشار و اصلاح فوری با مقصدهای توافق‌شدهFeature, release, and hotfix branches with agreed destinationsتفکیک صریح آماده‌سازی نسخه؛ هزینهٔ هماهنگی و ادغام بیشترExplicit release preparation; more coordination and integration overhead

این‌ها هم الزاماً انتخاب‌های کاملاً جدا نیستند. تیم می‌تواند trunk-based کار کند، PR را برای بازبینی به‌کار ببرد، و برای یک انتشار مشخص شاخهٔ موقت بسازد. اسم روش به‌اندازهٔ قواعد واقعی مهم نیست: کجا ادغام می‌کنیم، چه چیزی اجازهٔ merge دارد، انتشار از کدام commit است و fix فوری کجا می‌رود؟

These are not always mutually exclusive choices. A team can work trunk-based, use PRs for review, and cut a temporary branch for a specific release. The label matters less than the actual rules: where do we integrate, what can merge, which commit gets released, and where does an urgent fix go?

چهار تیم، چهار مسئلهٔ متفاوتFour teams, four different problems

بیایید اسم الگوها را کنار بگذاریم و از مسئله شروع کنیم. انتخاب زیر نسخهٔ نهایی برای همه نیست؛ فرض‌هایی است که هر تیم باید با تجربه و دادهٔ خودش امتحان کند.

Let's set the labels aside and start with the problem. The choices below are not universal prescriptions; they are hypotheses each team should test against its own experience and data.

تیم و محدودیتTeam and constraintمسیر معقول برای آزمایشA plausible path to tryسؤال / بهای باقی‌ماندهQuestion / remaining cost
سرویس وب؛ انتشار روزانه، CI خوب، قابلیت‌ها را می‌توان پنهان کردWeb service; daily releases, useful CI, features can be hiddentrunk-based با شاخه‌های کوتاه برای بازبینی؛ انتشار از main با flag برای بخش ناتمامTrunk-based with short review branches; release from main with flags for unfinished behaviorآیا CI آن‌قدر سریع است که trunk خراب زود دیده شود؟ چه کسی flag کهنه را حذف می‌کند؟Is CI fast enough to expose a broken trunk quickly? Who removes stale flags?
اپ موبایل؛ انتشار برنامه‌ریزی‌شده و تأیید فروشگاه، چند هفته فاصلهMobile app; scheduled releases and store approval, weeks apartادغام پیوسته در main به‌علاوهٔ شاخهٔ نسخه‌ انتشار کوتاه‌عمر بعد از انتخاب محتوای نسخهContinuous integration into main plus a short-lived release branch after scope is selectedاگر کاربران روی نسخهٔ قبلی مانده‌اند، fix امنیتی تا چه مدت باید backport شود؟If users remain on an older version, how long must security fixes be backported?
کتابخانه؛ نسخه‌های ۲ و ۳ هر دو پشتیبانی می‌شوندLibrary; both major versions 2 and 3 remain supportedخط توسعهٔ اصلی و شاخه‌های نگهداریِ محدود و روشن برای نسخه‌های پشتیبانی‌شدهA main development line plus bounded maintenance branches for supported versionsکدام commitها باید backport شوند؟ پایان پشتیبانی هر شاخه کی است؟Which commits should be backported? When does each branch reach end of support?
محصول قانون‌مند؛ تثبیت نسخه، تأیید چندنفره و مسیر ممیزی لازم استRegulated product; release stabilization, multi-person approval, and audit trail requiredPR و بررسیهای الزامی، حفاظت شاخه و در صورت نیاز نسخه‌ انتشار شاخه با مالک و بازهٔ مشخصPRs and required checks, branch protection, and—if needed—a release branch with an owner and time windowآیا شاخهٔ جدا واقعاً لازم است یا حفاظت و فرایند انتشار همان کنترل را ساده‌تر می‌دهند؟Is a separate branch truly needed, or can protection and release procedures provide the control more simply?

در تیم چهارم، کنترل رسمی را با تعداد شاخه اشتباه نگیر. بازبینی اجباری، بررسیهای لازم، محدودیت push و ثبت انتشار ممکن است روی یک شاخهٔ اصلی هم برقرار باشد. گاهی مدل چندخطی ارزش دارد؛ گاهی فقط کار را سخت می‌کند. الزام ممیزی باید با شاهدی که ممیز می‌خواهد شروع شود، نه با کپی‌کردن نمودار Git Flow.

For the fourth team, do not confuse formal control with branch count. Required reviews, checks, push restrictions, and release records can exist on a single main line. A multi-line model may sometimes be valuable; sometimes it only adds friction. Start from the evidence an audit requires, not by copying a Git Flow diagram.

حفاظت شاخه و CI، نگهبان مسیرند نه جایگزین سیاستBranch protection and CI guard the path; they are not the policy

اگر قرار است main همیشه قابل‌استقرار بماند، یا نسخه‌ انتشار فقط بعد از بررسی مشخص جلو برود، توافق شفاهی کافی نیست. می‌توانیم بخشی از آن را با CI و تنظیمات مخزن enforce کنیم. اما تنظیمی که نمی‌دانیم دقیقاً چه می‌کند، خودش می‌تواند مسیر همکاری را قفل کند.

If main should remain deployable, or a release may proceed only after specific checks, a verbal agreement may not be enough. CI and repository settings can enforce parts of the policy. But a setting whose behavior we do not understand can also block collaboration.

در GitHub، حفاظت شاخه می‌تواند بازبینی لازم، وضعیت بررسی لازم، حل گفت‌وگوهای باز، محدودیت push یا الزام به به‌روز بودن شاخه را تنظیم کند. merge queue هم برای شاخه‌های پرترافیک می‌تواند PRها را روی وضعیت تازهٔ مقصد و صف موجود دوباره بررسی کند. اینکه کدام قابلیت برای مخزن قابل‌دسترس است و چه ruleای برنده می‌شود، به تنظیمات و سطح دسترسی مخزن بستگی دارد؛ رفتار جاری را در مستندات همان میزبان بررسی کن.

On GitHub, branch protection can require reviews, status checks, resolved conversations, restrict pushes, or require a branch to be up to date. A merge queue can recheck PRs against the current target and queued changes for a busy branch. Availability and applicable rules depend on repository configuration and permissions; check the host's current documentation for the behavior that applies to your repository.

سبزشدن بررسی چه چیزی را ثابت می‌کند؟What does a green check prove?

فقط اینکه بررسی تعریف‌شده با همان commit یا ترکیبی که میزبان آزمایش کرده موفق بوده است. اگر تست مهمی در CI اجرا نمی‌شود، پیکربندی غلط است یا تعارض احتمالی فقط بعد از merge دیده می‌شود، علامت سبز تضمین کیفیت همه‌چیز نیست. سیاست شاخه باید بگوید چه بررسیهایی لازم‌اند و مالک نگهداری آن‌ها کیست.

Only that the configured check succeeded for the commit or merge candidate the host tested. If an important test is absent, the configuration is wrong, or a conflict appears only after integration, a green mark does not guarantee everything is correct. The branch policy should name required checks and who maintains them.

برای مخزنی که PR زیادی به main می‌فرستد، شرط «شاخه به‌روز باشد» ممکن است افراد را مجبور کند بارها update و CI را دوباره اجرا کنند. merge queue می‌تواند بخشی از این صف‌بندی را خودکار کند، اما صف، زمان اجرا و شکست بررسی هنوز هزینه دارند. ابزار، مسئلهٔ ظرفیت را حذف نمی‌کند؛ فقط ترتیب و قاعدهٔ ورود را روشن‌تر می‌کند.

For a repository with many PRs targeting main, an “up to date” requirement may make people repeatedly update branches and rerun CI. A merge queue can automate some of that serialization, but queue time, CI time, and failed checks still cost something. The tool does not erase the capacity problem; it makes ordering and entry rules clearer.

یک تصمیم کوچک‌تر از «انتخاب دائمی مدل»A smaller decision than “choose a model forever”

به تیم پنج‌نفره برگردیم. به‌جای پاک‌کردن همهٔ شاخه‌ها یا مهاجرت نمایشی، یک آزمایش محدود طراحی می‌کنیم: دو هفته تغییرهای معمول را کوچک‌تر کنیم، عمر شاخهها را ثبت کنیم و زمان انتظار برای merge و CI را ببینیم.

Return to the five-person team. Instead of deleting every branch or staging a dramatic migration, design a bounded experiment: for two weeks, make ordinary changes smaller, record branch lifetime, and observe merge and CI wait time.

از این داده‌ها سه چیز را می‌پرسیم: چند شاخه بیش از زمان توافق‌شده زنده ماند؟ چند بار لازم شد تغییرهای main را دیرهنگام بیاوریم؟ چند بار بررسی یا بازبینی معطل ماند؟ اگر جواب‌ها بدتر شدند، علت را از سیاست جدا کن: شاید CI کند است، شاید کارها بزرگ‌اند، شاید مالک بازبینی معلوم نیست. عوض‌کردن اسم مدل بدون رفع علت، مسئله را حل نمی‌کند.

Ask three things of the data: how many branches outlived the agreed window? How often did we bring main changes in late? How often were checks or reviews blocked? If results are poor, separate the cause from the label: CI may be slow, tasks may be too large, or review ownership unclear. Renaming the model without fixing the cause will not help.

نشانهٔ مسئلهSignalسؤال بعدیNext questionتغییری برای آزمایشChange to try
شاخهها مرتب چند روز بی‌خبر می‌مانندBranches regularly go days without integrationمی‌شود کار را به تغییرهای مستقل‌تر شکست؟Can the work be split into more independent changes?یک برش کوچک‌تر، PR باریک‌تر یا قابلیت flag موقتA smaller slice, narrower PR, or temporary feature flag
main گاهی بدون بررسی ادغام می‌شودMain sometimes receives unchecked changesکدام شاهد باید قبل از merge اجباری باشد؟What evidence must be required before merge?یک required بررسی مشخص و مالک روشن برای سلامت آنA specific required check with a clear maintainer
نسخه‌های منتشرشده نیاز به patch مستقل دارندReleased versions need independent patchesکدام خط واقعاً پشتیبانی می‌شود و تا چه زمانی؟Which lines are truly supported, and until when?شاخهٔ نگهداری محدود با مالک و قواعد backportA bounded maintenance branch with an owner and backport rules
PR پشت صف CI می‌ماندPRs queue behind CIصف از تعداد mergeهاست یا کندی خود testها؟Is the queue caused by merge volume or slow tests?بهینه‌کردن بررسیها، batch/merge queue یا تغییر زمان‌بندیImprove checks, use batching/merge queue, or adjust scheduling

تغییر سیاست را هم مثل تغییر کد بازبینی کن: یک نفر متن را بنویسد، بقیه با یک سناریوی واقعی آن را قدم‌به‌قدم اجرا کنند، و بعد از مدتی نتیجه را بسنجند. سیاستی که در صفحهٔ wiki زیباست اما هنگام اصلاح فوری معلوم نمی‌کند fix به کدام شاخه برود، هنوز سیاست کامل نیست.

Review a policy like a code change: one person drafts it, others walk through a real scenario step by step, and the team measures results later. A policy that looks neat in a wiki but cannot say where a hotfix goes is not complete yet.

پروژهٔ کوچک: سیاست شاخه‌بندی تیم شش‌نفرهMini-project: a branching policy for a six-person team

حالا به جای انتخاب یک اسم محبوب، برای یک تیم واقعی سیاست می‌سازی. تیم شش‌نفره است، هر هفته انتشار دارد و گاهی اصلاح فوری می‌خواهد. باید تصمیم بگیری شاخه‌ها چقدر عمر کنند، چه زمانی ادغام شوند و چه حفاظی روی main لازم است؛ هر تصمیم هم باید دلیل داشته باشد.

Now you are responsible for the team's agreement. Six people build one web product, release to production weekly, have CI, and work on several unfinished features at once. Sometimes they must ship an urgent hotfix to the live version. These facts do not automatically select a model; you must create a policy the team can actually follow.

یک سند یک‌صفحه‌ای بنویس. قبل از نوشتن، تصمیم بگیر آیا نسخه‌ انتشار شاخه کوتاه لازم است، آیا ادغام از راه PR انجام می‌شود، و قابلیت ناتمام چطور از کاربران پنهان می‌ماند. بعد دست‌کم دو گزینهٔ دیگر را کنار انتخابت بگذار و هزینه‌ای را که آگاهانه می‌پذیری بنویس. «سریع‌تر است» بدون توضیح CI، بازبینی و انتشار، دلیل کافی نیست.

Write a one-page policy. Before drafting, decide whether a short release branch is needed, whether integration goes through PRs, and how unfinished features stay hidden from users. Then compare at least two alternatives and name the cost you knowingly accept. “It is faster” is not enough without explaining CI, review, and release behavior.

بخش سندPolicy itemتصمیمی که باید روشن شودDecision to make explicit
عمر و نام شاخهBranch life and namingشاخهٔ عادی چقدر زنده می‌ماند؟ چه چیزی باعث می‌شود کار را کوچک‌تر کنیم؟How long does an ordinary branch live? What triggers splitting the work?
ادغام و بازبینیIntegration and reviewچه بررسیهایی لازم‌اند؟ چه کسی بررسی می‌کند؟ چه کسی مجاز است merge کند؟Which checks are required? Who reviews? Who may merge?
انتشار هفتگیWeekly releaseاز کدام commit یا شاخه نسخه می‌سازیم؟ چه کسی تصمیم «آماده است» را می‌گیرد؟From which commit or branch do we release? Who decides it is ready?
قابلیت ناتمامUnfinished featureآیا می‌شود امن ادغامش کرد؟ flag کی پاک و حالت‌هایش چطور تست می‌شوند؟Can it be integrated safely? Who removes the flag, and how are its states tested?
اصلاح فوریHotfixاز کدام نسخه شروع می‌شود؟ پس از انتشار کجا برمی‌گردد تا اصلاح گم نشود؟Which version does it start from? Where does it return after release so the fix is not lost?
بازنویسی تاریخچهHistory rewritingکدام شاخه خصوصی است و بازنویسی آن مجاز است؟ کدام خط مشترک را push اجباری نمی‌کنیم؟Which branches are private and rewritable? Which shared lines are never force-pushed?
راهنمای مرحله‌ایProgressive hint

یک گزینهٔ معقول برای شروع می‌تواند شاخه‌های تغییر کوتاه با PR و CI، ادغام پرتکرار در main، قابلیت flag برای کار واقعاً ناتمام، و شاخهٔ نسخه‌ انتشار فقط وقتی تثبیت هفتگی واقعاً لازم است باشد. اصلاح فوری باید از همان نسخهٔ production شروع شود و بعد از انتشار، طبق سیاست به main و هر خط پشتیبانی‌شده برگردد. این فقط نقطهٔ شروع بحث است؛ سرعت CI، الزام‌های محصول و مهارت تیم می‌تواند جواب را عوض کند.

One plausible starting point is short change branches with PR and CI, frequent integration to main, feature flags for genuinely unfinished work, and a release branch only when weekly stabilization truly needs one. A hotfix should start from the production version and return to main and any supported line after release. This is a discussion starter, not a universal answer; CI speed, product requirements, and team skills may change it.

پیش‌نویس را با دو سناریو امتحان کن: یک قابلیت سه‌روزه که هنوز برای کاربر روشن نیست، و یک خطای امنیتی در نسخهٔ production وقتی main چند تغییر ناتمام دارد. اگر برای هر کدام نتوانستی بگویی شاخه از کجا می‌آید، چه کسی چه چیزی را بررسی می‌کند، کجا merge می‌شود و نتیجه چطور دوباره verify می‌شود، جای خالی را در سند پیدا کرده‌ای.

Test the draft against two scenarios: a three-day feature that is not yet user-ready, and a security bug in production while main contains unfinished work. If you cannot say where each branch starts, who checks what, where it merges, and how the result is verified again, you have found a gap in the policy.

پاسخ نمونه و دلیل انتخابSample policy and rationale

برای این تیم می‌توان از GitHub Flow با شاخه‌های کوتاه شروع کرد، چون CI موجود است و انتشار هفتگی روی یک سرویس انجام می‌شود. ادغام به main فقط بعد از بازبینی و بررسیهای مشخص؛ قابلیت ناتمام با flag خاموش؛ شاخهٔ نسخه‌ انتشار فقط برای هفته‌هایی که نیاز واقعی به تثبیت جداگانه داریم و با تاریخ پایان؛ اصلاح فوری از tag نسخهٔ production، سپس merge همان اصلاح به main و هر نسخه‌ انتشار شاخه فعال. در برابر Git Flow کلاسیک، این سیاست شاخه‌های دائمی کمتری نگه می‌دارد، اما تیم باید برای آماده‌بودن main و تست flagها مسئولیت بپذیرد. در برابر trunk مستقیم، PR یک ایستگاه بازبینی اضافه می‌کند و ممکن است صف بسازد. اگر بعد از چند هفته انتظار بازبینی یا خرابی main زیاد بود، داده را بررسی و سیاست را اصلاح می‌کنیم.

This team could start with GitHub Flow and short-lived branches because it already has CI and releases one service weekly. Merge to main only after review and named checks; keep unfinished behavior behind a disabled flag; create a release branch only when separate stabilization is genuinely needed, with an end date; start a hotfix from the production tag, then merge the fix to main and any active release branch. Compared with classic Git Flow, this keeps fewer permanent branches but asks the team to own main readiness and flag tests. Compared with direct-to-trunk integration, PR adds a review checkpoint and may create a queue. If review waits or main breakages rise over several weeks, inspect the data and adjust the policy.

مدرک پایان پروژه فقط فایل سیاست نیست: دو نفر دیگر باید بتوانند با خواندنش هر دو سناریو را بدون حدس اجرا کنند. سیاست خوب قرار نیست اختلاف‌نظر را حذف کند؛ کاری می‌کند اختلاف قبل از production دیده شود و تصمیم بعدی معلوم باشد.

The project's proof is not just the policy document: two other people should be able to walk through both scenarios without guessing. A good policy does not eliminate disagreement; it makes disagreement visible before production and clarifies the next decision.

تمرین‌ها: به‌جای انتخاب شعار، سیاست طراحی کنExercises: design policies instead of choosing slogans

در این فصل جواب‌ها فرمان Git نیستند. باید از روی نیاز تیم، هزینهٔ ادغام، سرعت انتشار و کیفیت CI استدلال کنی. اگر دو راه هر دو منطقی‌اند، فرقشان را توضیح بده؛ لازم نیست برای هر سناریو یک «برندهٔ مطلق» بسازی.

For each case, first say what you do not yet know. Then state a proposal, its cost, and its success condition. The answers below model reasoning; they are not the only acceptable choices.

۱. پیش‌بینی هزینه1. Predict the cost

تیمی شاخهٔ قابلیت را ۱۰ روز باز نگه می‌دارد. Git تعارض نشان نداده. آیا می‌توان نتیجه گرفت ادغام بی‌هزینه است؟ چه شاهدی لازم است؟

A team keeps a feature branch open for ten days. Git reports no conflicts. Can you conclude integration is cost-free? What evidence is needed?

راهنماHint

تعارض متنی فقط یک نوع ناسازگاری است.

Textual conflict is only one kind of incompatibility.

نه. نبودن تعارض می‌گوید Git توانسته فایل‌ها را ترکیب کند، نه اینکه تست، API، ترتیب migration یا رفتار محصول سازگار است. شاخه را با main به‌روز کن، تست‌های یکپارچه را اجرا کن و رفتار مشترک را بازبینی کن؛ برای دفعات بعد عمر جدایی را هم اندازه بگیر.

No. No conflict means Git could combine the files, not that tests, APIs, migration order, or product behavior are compatible. Update against main, run integration tests, and review the combined behavior. For future work, measure how long branches stay separate.

۲. سرویس روزانه2. A daily service

یک سرویس وب روزی چند بار deploy می‌شود؛ تست سریع و قابلیت flag دارند. کدام مسیر را برای آزمایش پیشنهاد می‌دهی و کدام خطر می‌ماند؟

A web service deploys several times a day, has fast tests and feature flags. What path would you propose trying, and what risk remains?

راهنماHint

بسامد انتشار، بازخورد تست و پنهان‌کردن قابلیت ناتمام را با هم ببین.

Consider release frequency, test feedback, and how unfinished behavior is hidden.

trunk-based با تغییرهای کوچک و شاخه‌های بازبینی کوتاه، گزینهٔ معقولی برای آزمایش است. خطر باقی‌مانده این است که CI چیزی را نسنجد، main خراب بماند یا flag حالت‌های تست‌نشده بسازد؛ باید زمان بازخورد و سلامت trunk را پایش کنند.

Trunk-based development with small changes and short review branches is a plausible experiment. Remaining risks include gaps in CI, a broken main, and untested flag combinations; the team should watch feedback time and trunk health.

۳. آیا همه مستقیم روی main؟3. Does everyone commit directly to main?

همکارت می‌گوید: «trunk-based یعنی هیچ PRای نداریم.» این تعریف را چطور اصلاح می‌کنی؟

A teammate says, “Trunk-based means no PRs.” How would you correct that definition?

راهنماHint

مسئله، محل ادغام نهایی و طول جدایی است؛ نه صرفاً وجود PR.

The key is the integration destination and separation duration, not merely whether a PR exists.

trunk-based بر ادغام پرتکرار به یک خط مشترک و پرهیز از شاخه‌های توسعهٔ طولانی تأکید می‌کند. تیم می‌تواند بازبینی و CI را با شاخهٔ کوتاه و PR انجام دهد؛ مستقیم commit کردن هم در بعضی تیم‌ها انتخاب سیاست است، نه تعریف اجباری.

Trunk-based development emphasizes frequent integration to one shared line and avoiding long-lived development branches. A team can use short branches and PRs for review and CI; direct commits are a policy choice for some teams, not a required definition.

۴. مسیر GitHub Flow4. The GitHub Flow path

یک PR باز شده اما هیچ بررسیای برایش تنظیم نیست. آیا با نام GitHub Flow، merge خودکاراً بعد از بازبینی امن است؟

A PR is open, but no checks are configured. Does calling the workflow GitHub Flow make merging safe after review?

راهنماHint

یک مرحلهٔ گردش کار با قاعدهٔ حفاظت مخزن یکی نیست.

A workflow step is not the same as a repository protection rule.

نه؛ نام الگو تست نمی‌سازد. مستند رسمی GitHub مسیر شاخه، PR، بازبینی و merge را توضیح می‌دهد، اما بررسیهای لازم را تنظیم مخزن تعیین می‌کند. تیم باید بررسیهای لازم و قاعدهٔ ادغام را صریح کند و بعد مطمئن شود آن‌ها واقعاً اجرا می‌شوند.

No; a workflow label does not create tests. GitHub's official guide describes branches, PRs, review, and merge, while repository settings determine required checks. The team must name the checks and merge rules, then verify that they actually run.

۵. commit ناقص5. An incomplete change

قابلیت دو هفته‌ای است و فقط در انتهای کار کامپایل می‌شود. برای کوتاه‌شدن شاخه چه دو راهی را بررسی می‌کنی؟

A feature takes two weeks and compiles only at the end. What two options would you investigate to shorten the branch?

راهنماHint

یکی راهی در خود تغییر است؛ دیگری راهی در رفتار قابل‌مشاهدهٔ محصول.

One changes how the work is divided; the other changes what users can observe.

قابلیت را به قدم‌های سازگار و قابل‌ادغام بشکن، یا بخش رفتاری ناتمام را پشت قابلیت flag نگه دار تا کد قابل‌ساخت وارد trunk شود. هر دو نیازمند طراحی و تست‌اند؛ flag اگر حالت خاموش را خراب کند، صرفاً با ادغام زودتر مسئله‌ای تازه می‌سازد.

Split the feature into compatible, integrable steps, or keep unfinished behavior behind a feature flag so buildable code can reach trunk. Both require design and tests; if the off state is broken, a flag merely introduces a new problem.

۶. نسخه‌های پشتیبانی‌شده6. Supported versions

کتابخانه نسخه‌های ۲ و ۳ را پشتیبانی می‌کند. آیا Git Flow کامل الزام است؟ حداقل چه سیاستی باید مشخص باشد؟

A library supports versions 2 and 3. Is full Git Flow mandatory? What minimum policy must be defined?

راهنماHint

به شاخه‌های محدودِ نگهداری فکر کن، نه لزوماً همهٔ نقش‌های Git Flow.

Consider bounded maintenance branches, not necessarily every Git Flow role.

نه. ممکن است شاخه‌های نگهداری `release/2.x` و `release/3.x` با مالک و تاریخ پایان کافی باشند، در حالی که توسعهٔ تازه در main باشد. باید تعیین شود هر bugfix چگونه انتخاب و backport می‌شود، تست هر خط کدام است و پشتیبانی چه زمانی تمام می‌شود.

No. Maintenance branches such as `release/2.x` and `release/3.x` with owners and end dates may be enough while new development happens on main. Define how fixes are selected and backported, which tests apply to each line, and when support ends.

تا اینجا سه نام معروف را شناختی. از اینجا تمرین‌ها اسم الگو را ازت نمی‌خواهند؛ نیاز تیم را می‌دهند و ازت می‌خواهند سیاستی بسازی که با آن نیاز جور باشد.

You now know the three well-known names. From here the exercises do not ask you to recite a model; they give you a team constraint and ask you to design a policy that fits it.

۷. نقش develop7. The role of develop

تیمی `develop` دارد اما هر commit آن بلافاصله deploy می‌شود و هفته‌ای چند بار هم از main با آن merge می‌کند. چه چیزی باید بررسی شود؟

A team has `develop`, deploys every commit from it immediately, and merges it with main several times a week. What should it investigate?

راهنماHint

بپرس تفاوت قابل‌مشاهدهٔ دو خط چیست و چه کسی به آن نیاز دارد.

Ask what observable difference the two lines provide and who needs it.

باید بپرسند develop چه مرز معنایی‌ای دارد که main ندارد. اگر هیچ تفاوتی در ثبات، انتشار یا مالکیت نیست، شاید شاخه اضافه فقط مسیر ادغام دوگانه و تعارض می‌سازد. اگر تفاوت واقعی هست، آن را در سیاست و بررسیها توضیح دهند؛ صرف وجود نام `develop` دلیل کافی نیست.

They should ask what semantic boundary develop provides that main does not. If stability, release, and ownership are identical, the extra branch may only create a second integration path and conflicts. If a real distinction exists, document it in the policy and checks; the name alone is not a reason.

۸. نسخه‌ انتشار شاخه8. A release branch

تیم موبایل از main انتشار می‌دهد ولی تأیید فروشگاه چند هفته طول می‌کشد؛ در این فاصله باید crash fix بدهد. یک گزینهٔ معقول و شرطش را بگو.

A mobile team releases from main, but store approval takes weeks; it must ship crash fixes during that time. Give one plausible option and its condition.

راهنماHint

برای نسخه‌ای که منتظر تأیید است، مقصد patch را از mainِ توسعه جدا کن؛ اما راه برگشت را فراموش نکن.

Separate the patch destination for the release awaiting approval from development main, but do not forget the path back.

بعد از انتخاب محتوای نسخه، یک نسخه‌ انتشار شاخه محدود بسازند تا اصلاح‌های تأییدشده به همان نسخه برسد؛ شاخه باید مالک، تست و پایان مشخص داشته باشد و fixها به main هم برگردند. اگر اصلاح‌ها را می‌توان بدون شاخه روی نسخهٔ منتشرشده patch کرد، ممکن است فرآیند ساده‌تری کافی باشد.

After selecting release scope, create a bounded release branch for approved fixes to that version, with an owner, tests, and end date; fixes must also return to main. If releases can be patched without a branch, a simpler process may suffice.

۹. اصلاح فوری از کجا؟9. Where does a hotfix start?

در Git Flow کلاسیک، main نسخهٔ زنده را نشان می‌دهد و develop تغییرهای ناتمام دارد. اصلاح فوری بحرانی باید از کجا شروع شود و بعد از انتشار چه شود؟

In classic Git Flow, main represents the live version and develop contains unfinished work. Where should a critical hotfix start, and what happens after release?

راهنماHint

فقط رساندن fix به نسخهٔ فعلی کافی نیست؛ خط بعدی هم باید آن را بگیرد.

Fixing the current release is not enough; the next development line must receive it too.

از commit یا tag نسخهٔ زنده شروع کن، نه از develop ناپایدار. بعد از تست و انتشار، اصلاح باید به main برسد و به خط‌های توسعهٔ فعال هم برگردد؛ اگر نسخه‌ انتشار شاخه فعالی وجود دارد، مقصدها را طبق سیاست هماهنگ کن تا fix دوباره گم نشود.

Start from the live commit or tag, not unstable develop. After testing and release, the fix must reach main and active development lines; if a release branch is active, coordinate destinations according to policy so the fix is not lost again.

۱۰. تغییر بدون تعارض10. A conflict-free change

merge شاخه طولانی بدون تعارض تمام شد ولی تست end-to-end شکست خورد. کدام فرض اشتباه بود؟ قدم بعدی چیست؟

A long branch merged without conflicts, but end-to-end tests failed. Which assumption was wrong, and what comes next?

راهنماHint

خروجی تست و تفاوت commitهای دو سمت را کنار هم بگذار.

Compare the test output with the commits contributed by each side.

فرض اشتباه این بود که «merge تمیز» یعنی رفتار ترکیبی درست است. ابتدا خروجی تست و تفاوت ورودی‌های main/branch را بررسی کن، بازتولید را روی merge result انجام بده و ناسازگاری را اصلاح کن. بعد همان آزمون end-to-end را دوباره اجرا کن؛ صرف موفقیت merge مدرک سلامت نیست.

The mistaken assumption was that a clean merge means the combined behavior is correct. Inspect the test output and differences from main and the branch, reproduce on the merge result, and fix the incompatibility. Then rerun the same end-to-end test; a successful merge is not proof of health.

۱۱. حفاظت شاخه11. Branch protection

main محافظت می‌شود و یک required بررسی همیشه سبز است، اما تیم می‌گوید تست ادغام اصلاً در CI نیست. آیا حفاظت کافی است؟ چه تغییری لازم است؟

Main is protected and one required check is always green, but the team says integration tests are absent from CI. Is protection sufficient? What needs to change?

راهنماHint

قاعدهٔ حفاظت فقط بررسیای را می‌بیند که به آن معرفی شده است.

The protection rule sees only the check it has been configured to require.

نه؛ ابزار فقط همان بررسی تعریف‌شده را enforce می‌کند. تست ادغام را اضافه و با نتیجهٔ درست به commit/PR وصل کن، نام بررسی را در rule لازم کن و عمداً یک شکست کنترل‌شده را امتحان کن تا مطمئن شوی merge واقعاً مسدود می‌شود.

No; the tool enforces only the configured check. Add integration tests, connect their actual result to the commit/PR, require that check in the rule, and run a controlled failure to confirm that merging is blocked.

۱۲. merge queue چه چیزی را حل می‌کند؟12. What does a merge queue solve?

یک مخزن شلوغ PRهای زیادی دارد که هر کدام جداگانه سبزند، اما گاهی ترکیب دو PR با هم ساخت را می‌شکند. merge queue چه کمکی می‌کند و چه چیزی را تضمین نمی‌کند؟

A busy repository has many individually green PRs, but combinations sometimes break the build. How can a merge queue help, and what does it not guarantee?

راهنماHint

مشکل را در ترکیب PRها روی مقصد به‌روز جست‌وجو کن، نه تست هر PR به‌تنهایی.

Look at combinations applied to the updated target, not only each PR in isolation.

merge queue می‌تواند تغییر را در ترتیب صف روی پایهٔ به‌روز و PRهای جلوتر بررسی کند و سپس طبق تنظیمات merge کند. این کار ناسازگاری ترکیبی را زودتر می‌گیرد، اما تست ناکافی را کامل نمی‌کند و موفقیت deployment یا عملکرد در production را تضمین نمی‌کند.

A merge queue can test a change in queue order against the updated base and preceding PRs, then merge according to configuration. This can catch integration incompatibility earlier, but it cannot complete inadequate tests or guarantee deployment or production behavior.

در تمرین‌های آخر ممکن است بیش از یک سیاست قابل دفاع باشد. جواب خوب باید هزینهٔ راه انتخابی را هم بگوید: ادغام دیرتر، نیاز به CI قوی‌تر، یا پیچیدگی بیشتر در انتشار.

In the final exercises, more than one policy may be defensible. A good answer also names the cost of the chosen approach: later integration, stronger CI needs, or more release complexity.

۱۳. flagهای انباشته13. Accumulating flags

trunk با پنج flag قدیمی و حالت‌های ترکیبی تست‌نشده پر شده. آیا راه‌حل فقط کوتاه‌ترکردن شاخههاست؟ پیشنهادت را با دو خطر بنویس.

Trunk has five stale flags and their combinations are untested. Is shortening branches the only fix? Give a proposal and two risks.

راهنماHint

طول عمر شاخه و طول عمر قابلیت flag را با هم یکی نگیر.

Do not confuse branch lifetime with feature-flag lifetime.

نه. برای flagها مالک و تاریخ حذف تعیین کن، حالت‌های روشن/خاموش مهم را تست کن و flagهای تمام‌شده را پاک کن. کوتاه‌کردن شاخه ادغام را بهتر می‌کند اما flag debt را درمان نمی‌کند؛ نگه‌داشتن flagهای بیشتر هم پیچیدگی حالت‌ها و احتمال رفتار ناخواسته را بالا می‌برد.

No. Assign each flag an owner and removal date, test meaningful on/off states, and remove completed flags. Shorter branches improve integration but do not cure flag debt; keeping more flags also increases state complexity and the chance of unexpected behavior.

۱۴. نیاز ممیزی14. An audit requirement

ممیز می‌خواهد بداند چه کسی تأیید کرده، کدام تست گذشت و کدام بستهٔ نرم‌افزاری منتشر شده. مدیر می‌گوید پس حتماً Git Flow می‌خواهیم. پاسخ دقیق‌تر چیست؟

An auditor wants to know who approved, which tests passed, and which artifact was released. A manager says this means Git Flow is required. What is a more precise response?

راهنماHint

اول بپرس ممیز چه چیزی را می‌خواهد ردیابی کند؛ شاخه فقط یکی از راه‌های سازمان‌دهی است.

First ask what the auditor needs to trace; a branch is only one way to organize work.

این نیازها را می‌توان با PR و بازبینی ثبت‌شده، بررسیهای لازم، tag یا شناسهٔ دقیق بسته و ثبت استقرار پوشش داد؛ Git Flow یکی از گزینه‌هاست فقط اگر خط‌های نسخه‌ انتشار جدا واقعاً به تثبیت نیاز دارند. ابتدا نوع مدرک و قواعد نگهداری را از ممیز روشن کن، سپس ساده‌ترین جریان قابل‌ممیزی را انتخاب کن.

Recorded PR reviews, required checks, exact tags or artifact IDs, and deployment records can meet these needs; Git Flow is an option only if separate release lines are genuinely needed for stabilization. Clarify the required evidence and retention rules with the auditor, then choose the simplest auditable flow.

۱۵. حمایت از دو نسخه15. Supporting two versions

تیمی سه شاخهٔ نسخه‌ انتشار دائمی دارد اما تنها یک نسخه واقعاً پشتیبانی می‌شود. چه چیزی را باید بازبینی کند؟

A team has three permanent release branches, but only one version is actually supported. What should it review?

راهنماHint

به مصرف‌کنندهٔ نسخهٔ قدیمی و سامانه‌ای که از شاخه استفاده می‌کند فکر کن.

Consider users of old versions and systems that may still depend on the branch.

شاخه‌های بدون مصرف‌کننده و تعهد مشخص را ببندد یا حذف کند، بعد سند پشتیبانی را با نسخه‌ انتشار واقعی هماهنگ سازد. قبل از حذف، مطمئن شود tagها و بسته‌های منتشرشده برای ارجاع نسخه‌های قبلی کافی‌اند و هیچ استقرار فعالی به آن شاخه وابسته نیست. شاخهٔ بلااستفاده را با «شاید روزی لازم شود» بی‌انتها نگه ندار.

Close or retire branches with no users or support commitment, then align the support policy with actual releases. Before deletion, confirm tags and artifacts are enough to identify old releases and no active deployment depends on the branch. Do not keep unused branches forever because they might be useful someday.

۱۶. صف بازبینی16. Review queue

تیم به شاخه‌های کوتاه مهاجرت کرده اما PRها سه روز منتظر بازبینی می‌مانند. آیا شاخه کوتاه به‌تنهایی موفقیت است؟ دو اقدام مشخص پیشنهاد کن.

A team moved to short branches, but PRs wait three days for review. Is short branch lifetime alone a success? Suggest two concrete actions.

راهنماHint

گلوگاه ممکن است در بازبینی باشد، نه در خود Git یا branch.

The bottleneck may be review, not Git or the branch itself.

خیر؛ جدایی کد کوتاه شده ولی گلوگاه انسانی باقی است. PRها را کوچک‌تر و مالک بازبینی را چرخشی/مشخص کن، و زمان انتظار را اندازه بگیر. شاید لازم باشد ظرفیت CI یا قاعدهٔ دو تأیید را هم متناسب کنی؛ تعداد شاخه کمتر به‌تنهایی جریان را سریع نمی‌کند.

No; code separation is shorter, but the human bottleneck remains. Make PRs smaller, assign clear or rotating review ownership, and measure wait time. CI capacity or a two-approval rule may also need adjustment; fewer branches alone do not speed up flow.

۱۷. دو جریان را ترکیب کن17. Combine two practices

یک تیم می‌خواهد trunk-based بماند، ولی قبل از merge از همکار بازبینی بگیرد. یک مسیر سازگار بنویس و شرط مهم آن را بگو.

A team wants to remain trunk-based but requires peer review before merge. Write a compatible path and state its key condition.

راهنماHint

شاخه برای بررسی است یا قرار است مدتی محل توسعهٔ روزانه باشد؟

Is the branch for review, or will it become the place for ongoing daily development?

تغییر کوچک روی شاخهٔ کوتاه ایجاد شود، CI و بازبینی سریع انجام شوند، شاخه به trunk ادغام و سپس حذف شود. شرط مهم این است که شاخه به محل توسعهٔ بلندمدت و اشتراکی تبدیل نشود؛ بازخورد باید سریع باشد و trunk همچنان مرکز مشترک ادغام بماند.

Make a small change on a short-lived branch, run CI and review quickly, integrate it into trunk, then delete the branch. The key condition is that the branch must not become a long-lived shared development line; feedback should be fast and trunk remain the shared integration center.

۱۸. تصمیم برای تیم داستان18. Decide for the team in the story

برای تیم پنج‌نفرهٔ ابتدای فصل، فقط یک تغییر فوری انتخاب کن و بگو در دو هفتهٔ بعد چه داده‌ای جمع می‌کنی تا بفهمی سیاست جواب داده یا نه. پاسخ باید هم هزینه و فایده را بگوید، هم چیزی را که هنوز ثابت نشده.

Choose one immediate change for the five-person team from the opening. State what data you would collect over the next two weeks to evaluate the policy. Your answer must name a trade-off and something that remains unproven.

راهنماHint

یک آزمایش محدود بهتر از مهاجرت همه‌چیز است.

A bounded experiment is better than migrating everything at once.

مثلاً برای کار تازه شاخههای تغییر کوتاه با سقف عمر توافقی، PR کوچک و بررسی سریع را آزمایش می‌کنم. عمر شاخه، زمان انتظار بازبینی، دفعات تعارض و شکست main را ثبت می‌کنم. این انتخاب یک ایستگاه بازبینی/CI اضافه می‌کند. هنوز معلوم نیست علت همهٔ تعارض‌ها طول شاخه بوده؛ ممکن است مالکیت فایل یا معماری عامل اصلی باشد، پس دادهٔ دو هفته‌ای فقط سرنخ است، نه اثبات علیت.

For example, I would trial short-lived change branches with an agreed lifetime, small PRs, and a fast required check. Record branch age, review wait, conflict frequency, and main breakages. The trade-off is an extra review/CI checkpoint. It is not yet clear that branch lifetime caused every conflict; file ownership or architecture may be the real factor, so two weeks of data is a clue, not proof of causation.

هر سیاستی انتخاب کنی، نوبت همکاری با آدم‌هاستWhichever policy you choose, collaboration with people comes next

هر سیاست شاخه‌بندی که انتخاب کنی، در نهایت یک آدم باید تغییر آدم دیگری را بفهمد و بررسی کند. فصل بعد از گراف فاصله می‌گیرد و وارد خودِ همکاری می‌شود: commit خوب، درخواست ادغام خوب و بازبینی قابل اعتماد.

Choosing a branching policy does not finish the collaboration problem; it reveals how changes are presented to others. The next chapter turns to pull requests and code review: how to prepare commits and explanations that let a teammate review with confidence, ask the right questions, and see risk before merge.

مرور سریع این فصلQuick reference

اگر این نیاز را داری…If you need…این مسیر را بررسی کن…Consider…و این را هم بسنج…Also evaluate…
ادغام زود و انتشار پرتکرارEarly integration and frequent releasestrunk-basedسرعت CI، سلامت trunk، قابلیت‌های ناتمامCI speed, trunk health, unfinished features
بازبینی روشن روی هر تغییرA clear review path for every changeGitHub Flow یا معادل میزبانالزام واقعی بررسیها، طول شاخه، روش deploymentActual required checks, branch lifetime, deployment method
آماده‌سازی نسخه و چند خط پشتیبانیRelease stabilization and multiple support linesGit Flow کلاسیک یا شاخه‌های نگهداری محدودهزینهٔ merge، backport، مالک و پایان هر شاخهMerge cost, backports, branch owners, and end dates

پیش از ثبت سیاستBefore you publish the policy

یک سناریوی عادی و یک اصلاح فوری را با آن قدم‌به‌قدم اجرا کن. اگر معلوم نیست شاخه از کجا شروع می‌شود، چه بررسیی لازم است، کجا merge می‌شود و اصلاح چطور به نسخه‌های بعد می‌رسد، هنوز جای تصمیم خالی است. الگو را برای مسئله انتخاب کن، بعد از چند هفته اثرش را با داده بسنج.

Walk through one ordinary change and one hotfix step by step. If the policy does not say where a branch starts, which checks are required, where it merges, and how the fix reaches future versions, a decision is still missing. Choose a model for the problem, then evaluate its effect with data after a few weeks.