Course contentsShow
← Git & GitHub
Lesson 42 of 963. Branching and TeamworkFree lesson

Establishing Branching Workflows for Parallel Tasks

You will implement a structured branching strategy to manage multiple concurrent tasks effectively while maintaining a clean and deployable main project branch.

In this lesson, you will learn how to structure your branching strategy to manage multiple concurrent tasks without cluttering your stable code.

The Strategy of Parallel Workflows

When working on a project, you often have a "stable" version of your code that is ready for deployment (usually stored on the main branch). If you work on several features or bug fixes simultaneously, doing everything directly on main causes chaos. Instead, we use a structured workflow where main acts as the source of truth, and temporary branches act as isolated "workbenches."

How to Manage Concurrent Tasks

The goal is to ensure that your main branch always remains in a clean, deployable state. Here is the standard cycle for a task-oriented workflow:

  1. Start from Clean State: Always ensure your main branch is updated and clean before starting a new task.
  2. Create Feature-Specific Branches: For every new task, create a unique branch named after the feature or fix.
    git checkout main
    git pull origin main
    git checkout -b feature/login-page
    
  3. Isolate and Develop: Perform your work, stage your changes, and commit them only to the feature/login-page branch. If a sudden, urgent bug arises, you can simply switch back to main, create a hotfix/emergency-patch branch, and resolve it without interrupting your current feature progress.
  4. Integrate and Clean: Once a feature is finished and tested, merge it back into main and delete the feature branch to keep your repository history tidy.

Why This Works

By creating a new branch for every distinct piece of work, you gain two major advantages:

  • Context Switching: If you are halfway through a feature and need to pause to fix a bug, you can stash your changes or simply commit them to the current branch. You then switch to main to create your fix branch, keeping your files organized and preventing "half-finished" code from polluting your production-ready branch.
  • Parallelism: You can have a feature/search branch and a feature/dark-mode branch existing at the same time. Neither affects the other until they are ready to be merged into main.

Key Takeaway: Always isolate each unique task in its own branch to keep your main branch stable, searchable, and ready for deployment.