main stable while you implement fixes or features, and it links your code changes directly to the issue for clearer traceability.
Why create a branch from an Issue?
- Keeps the
mainbranch stable and deployable. - Attaches context (the issue) to the work you do, improving traceability.
- Simplifies producing a focused pull request that references the issue.
Create a branch from the GitHub Issues UI
- Open the Issue you want to work on.
- Locate the “Development” section in the issue sidebar.
- Click “Create branch”.
- Choose the destination repository and the source branch (commonly
main). - Confirm the branch name or edit it before creation.
GitHub suggests a branch name by default using the issue number and a slugified title (for example,
1-fix-exponential-growth-bug). You can rename it to match your repo’s branch naming conventions (e.g., issue/1/multi-ball-fix).Fetch and check out the branch locally
Use eithergit checkout or git switch --track, depending on your Git version and preference. Example commands provided by GitHub:
git switch:
Once checked out, the new branch will reflect
main at the moment it was branched.
Example issue: Multi-ball power-up causing exponential growth
Below is a sample issue describing an in-game bug: activating a multi-ball power-up duplicates balls in a way that leads to exponential growth and performance issues. Problematic code:- The
forEachiterates overgameState.ballswhile the loop body pushes new balls into the same array. - Adding clones during iteration allows newly pushed balls to be iterated later in the same activation, causing the array to grow exponentially: 1 → 2 → 4 → 8…
- The guard
gameState.balls.length < 5only gates entering the duplication block; it does not prevent overshooting the intendedMAX_BALLS.
This pattern leads to exponential growth of the array and can quickly exceed intended limits, causing performance degradation or crashes. Always avoid mutating the iterated array in ways that change its length during the loop.
Safer implementation
Capture a snapshot of the array before duplicating and enforce a maximum cap while adding clones only up to the limit:originalBallsis a shallow copy taken before adding any new balls, so newly appended balls are not re-duplicated in the same activation.- The loop checks
gameState.balls.lengthon each iteration and breaks onceMAX_BALLSis reached, preventing overshoot.
Complete workflow summary
Links and References
By creating branches directly from issues and following a guarded duplication pattern shown above, you keepmain stable and avoid bugs that can lead to exponential growth and performance problems.