Skip to main content
Learn how and why to create a branch from a GitHub Issue, then fetch and work on that branch locally. Creating branches from issues helps keep 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 main branch 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

  1. Open the Issue you want to work on.
  2. Locate the “Development” section in the issue sidebar.
  3. Click “Create branch”.
  4. Choose the destination repository and the source branch (commonly main).
  5. 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).
When GitHub creates the branch it also displays the commands you can run locally to fetch and check it out.

Fetch and check out the branch locally

Use either git checkout or git switch --track, depending on your Git version and preference. Example commands provided by GitHub:
Or using git switch:
Quick reference of common commands: 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:
Why this is problematic:
  • The forEach iterates over gameState.balls while 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 < 5 only gates entering the duplication block; it does not prevent overshooting the intended MAX_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:
Why this works:
  • originalBalls is 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.length on each iteration and breaks once MAX_BALLS is reached, preventing overshoot.

Complete workflow summary

By creating branches directly from issues and following a guarded duplication pattern shown above, you keep main stable and avoid bugs that can lead to exponential growth and performance problems.

Watch Video